如何将.animate更改为.css,这样它就不会与CSS3动画发生冲突
How to change .animate to .css so it doesn't conflict with a CSS3 animation?
下面是我用来浏览CSS3幻灯片的部分代码,该幻灯片使用立方bezier动画并使用关键帧计时。
现在这行代码…
$("#carousel .video-list").animate({'left' : left_indent}, 1000, function () {
…与我现有的css冲突,因为我知道它们不能一起使用。我的问题是,我如何编辑这行代码,使它是。css而不是。animate为了它的功能,而不是与我的css3动画冲突?
演示JS
var item_width = $("#carousel .video-list li").outerWidth();
var left_value = item_width * (-1);
//if user clicked on prev button
$('#previous').click(function () {
//get the right position
var left_indent = parseInt($("#carousel .video-list").css('left')) + item_width;
//slide the item
$("#carousel .video-list").animate({'left' : left_indent}, 1000, function () {
$(".video-list, #timeline, .description-list").css({"animation-play-state": "paused",
"-webkit-animation-play-state": "paused"});
//move the last item and put it as first item
$("#carousel .video-list li:first").before($("#carousel .video-list li:last"));
//set the default item to correct position
$("#carousel .video-list").css({'left' : left_value});
$("#myVideo").get(0).play();
$("#myVideoTwo").get(0).play();
$("#myVideoThree").get(0).play();
$("#myVideoFour").get(0).play();
});
//cancel the link behavior
return false;
});
任何帮助都将是感激的,非常感谢!
无论如何,这都不是一个跨浏览器的解决方案,但是您仍然可以使用CSS来执行此操作并侦听transitionend
事件。Javascript看起来像这样:
$("#carousel .video-list").bind( 'transitionend', function() {
$(".video-list, #timeline, .description-list").css({"animation-play-state": "paused", "-webkit-animation-play-state": "paused"});
// More code that's currently in the animation complete handler
});
$("#carousel .video-list").css({ left : left_indent
transition : 'all 1000ms linear'});
如果这解决了你的问题,我不保证,但听起来你正在寻找一种方法,让.animate()
完成事件处理程序触发当前在那里的事件的代码,尽管你正在使用CSS转换。
顺便说一下,jQuery将使你传递到.css()
方法的transition
属性自动跨浏览器(即在必要时包括供应商前缀)
同样值得注意的是,你可以监听另一个事件来处理正在结束的动画。您可以绑定到animationend
,而不是transitionend
。
这个函数不在click函数中:
$("#carousel .video-list").animate({'left' : left_indent}, 1000, function () {
将函数拉到它的外部并使用:
function animateList(left_indent) {
然后在你的click函数中把它改成:
var item_width = $("#carousel .video-list li").outerWidth();
var left_value = item_width * (-1);
$('#previous').click(function () {
//get the right position
var left_indent = parseInt($("#carousel .video-list").css('left')) + item_width;
//slide the item
animateList(left_indent);
//cancel the link behavior
return false;
});
更新animateList()函数
function animateList(left_indent) {
$(".video-list, #timeline, .description-list").css({"animation-play-state":"paused", "-webkit-animation-play-state": "paused"});
//move the last item and put it as first item
$("#carousel .video-list li:first").before($("#carousel .video-list li:last"));
//set the default item to correct position
$("#carousel .video-list").css({'left' : left_value});
$("#myVideo").get(0).play();
$("#myVideoTwo").get(0).play();
$("#myVideoThree").get(0).play();
$("#myVideoFour").get(0).play();
}
这将删除javascript动画,这样你就可以使用基于left属性的CSS过渡。
#carousel .video-list {
-webkit-transition: left ease 2s; /* For Safari 3.1 to 6.0 */
transition: left ease 2s;
}
相关文章:
- 关键帧之间的css3动画延迟
- 访问css3动画的关键帧
- CSS3动画图像质量按比例
- jQuery鼠标输出调用CSS3动画
- 使用带有onclick事件的Javascript启动CSS3动画
- 在 CSS3 动画完成后重新加载 JavaScript
- 如何正确地链接调用$.show()和$.thoggClass()来触发CSS3动画
- css3动画文本居中对齐
- Chrome在尝试从Javascript修改CSS3动画时崩溃
- 如何用Javascript覆盖CSS3动画
- 在没有关闭H/W加速的情况下优化CSS3动画会让它在GPU上运行得更快吗
- 如何使用JavaScript对象编写CSS3动画
- jQuery有没有,或者有没有jQuery插件,内置了监听CSS3动画事件的功能(例如animationEnd)
- 如何内联或通过javascript设置css3动画
- css3动画使用html5数据属性
- css3 动画中的虚线边框动画
- CSS3 动画和 JavaScript 类切换后的动画出现问题
- 停止并重新启动 CSS3 动画
- 展开 CSS3 动画不起作用
- CSS3 动画 - 无限悬停箭头