基本上,我有一个非常简单的(做一个改变)滑块,是用css完成的。导航按钮有标签,它们对每一张幻灯片都是独一无二的。的问题是,只有当幻灯片导航到.时,我才能将类添加/移除到幻灯片中的某些项中。
与滑块一样,当滑块加载时,它们倾向于加载所有的内容,我希望在幻灯片上添加一些很酷的动画,因此,如果所有的内容都加载在幻灯片上,那么就没有意义了。
我提供了一些模拟滑块和动画类和淡出类,在这种情况下,我想在特定的幻灯片加载中添加和删除。然后我会把它们分配到幻灯片上的不同部分..。
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.fadeInUpBig {
-webkit-animation-name: fadeInUpBig;
animation-name: fadeInUpBig;
opacity: 0.3;
background-color: rgba(0,0,0,0.3);
}发布于 2015-06-11 14:27:19
CSS允许您创建带有转换和关键帧的动画,这些动画曾经只有在JavaScript或Flash中才能实现。不幸的是,使用CSS无法在动画完成时执行回调。使用JavaScript,可以检测CSS转换或动画的结束,然后触发函数。
使用JavaScript,我们可以检测过渡事件;但是对于跨浏览器,我们需要包括其他浏览器的前缀。
$(function() {
//Store a ref to slides
var $slides = $(".slides");
//Bind event to the contianed that gets animated
$(".slide-container")
.on("transitionend webkitTransitionEnd oTransitionEnd msTransitionEnd", function(e){
// Remove classes from all the elements within the active container that starts with the class 'add-anim'
$slides.find(".slide-container [class^='add-anim']").removeClass("animated bounceInLeft bounceInUp");
//Add appropriate classes to the matched elements within the active container
var $radio = $slides.find(":radio[name='radio-btn']:checked");
$radio.next(".slide-container").find(".add-anim-up").addClass("animated bounceInUp");
$radio.next(".slide-container").find(".add-anim-left").addClass("animated bounceInLeft");
});
});这是你的整段代码和HTML+JS+CSS。
注意:上面的解决方案可以工作,但问题是,取决于浏览器,它可以触发两次(即Chrome支持webkitTransitionEnd和过渡端)。但是,有一些方法可以通过检测受支持的事件属性来克服这一点。以看这个演示为例了解更多细节。
希望这能有所帮助。
https://stackoverflow.com/questions/30780322
复制相似问题