Cra*_*lot 5 javascript jquery animation mobile-safari css3
如何检测刚刚在JavaScript中完成的CSS动画?
最终需要是重新触发CSS动画.由于我们的HTML层次结构,我们不希望检查元素的类,而是仅在特定动画结束时才采取操作.如果您的方法允许在不删除/添加课程的情况下重新触发动画,请告诉我们.
否则...我们的代码:
page.find( '.button.letter' ).on( 'webkitAnimationEnd', function() {
$( this ).removeClass( 'tap_animation' );
console.log( 'Hi: ' + this.style.webkitAnimationName );
if ( !write_mode() ) {
do_write( this );
}
});
Run Code Online (Sandbox Code Playgroud)
this.style.webkitAnimationName始终返回空字符串.
我们做错了吗?
我们需要WebKit浏览器的代码,特别是Mobile Safari.
谢谢!
您可以从 jQuery 访问originalEvent对象,并从那里访问animationName属性:
$('body').on('webkitAnimationEnd', function(e){
var animName = e.originalEvent.animationName;
console.log(animName);
});?
Run Code Online (Sandbox Code Playgroud)
从那里,只需使用 anif来检查动画名称是/曾经是什么(我想是过去式,因为它结束了)。
以上已更新,以提供更好的说明:
$('div').on('webkitAnimationEnd', function(e){
var animName = e.originalEvent.animationName;
if (animName == 'bgAnim') {
alert('the ' + animName + ' animation has finished');
}
});?
Run Code Online (Sandbox Code Playgroud)
此演示使用以下 HTML:
<div><span>text</span></div>?
Run Code Online (Sandbox Code Playgroud)
和 CSS:
@-webkit-keyframes bgAnim {
0%, 100% {
color: #000;
background-color: #f00;
}
50% {
color: #fff;
background-color: #0f0;
}
}
@-webkit-keyframes fontSize {
0%, 100% {
font-size: 100%;
}
50% {
font-size: 300%;
}
}
div {
font-weight: bold;
-webkit-animation: bgAnim;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: 2;
}
span {
font-size: 100%;
font-weight: bold;
-webkit-animation: fontSize;
-webkit-animation-duration: 4s;
-webkit-animation-iteration-count: 1;
}
Run Code Online (Sandbox Code Playgroud)