gpt4 book ai didi

jquery html5 webkit-动画回调

转载 作者:行者123 更新时间:2023-11-28 00:20:34 24 4
gpt4 key购买 nike

webkit-animation complete有回调吗?见example

@-webkit-keyframes "blink" {
0% { opacity: 1; }
100% { opacity: 0; }
}
.animate {
background: #000;
height: 100px;
width: 100px;
opacity: 0;
-webkit-animation-direction: normal;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: 1;
-webkit-animation-name: blink;
-webkit-animation-timing-function: ease;
}​

$("div").bind("webkitTransitionEnd", function() {
alert(1);
}).addClass("animate");​

但是这个回调不起作用

最佳答案

这样就可以了:

element.addEventListener('webkitAnimationEnd', function(event) { });

在 firefox 中,该事件称为“animationend”,但一些 webkit 浏览器会同时收听这两个事件。相反,如果你使用 jquery,你可以做的是使用

$element.on('webkitAnimationEnd animationend' , function(event){ });


更新:

我最近在使用 .one('webkitAnimationEnd animationend') 时遇到了一个小事故,因为这两个事件都在 chrome 中被监听,但一次只触发一个,相同的函数将触发两次两个独立的动画结束事件。

取而代之的是一个小技巧,可以使用类似于此的函数:

getTransitionEndEvent : function(){
switch(this._currentBrowser){
case enums.Browser.SAFARI:
case enums.Browser.CHROME:
return "webkitTransitionEnd";
case enums.Browser.FIREFOX:
return "transitionend";
default:
console.log("unknown browser agent for transition end event");
return "";
}
}

并根据需要添加更多供应商特定的前缀。

为了识别浏览器我真的可以推荐这个:

How to detect Safari, Chrome, IE, Firefox and Opera browser?

关于jquery html5 webkit-动画回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9261324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com