admin管理员组文章数量:1290500
I'm trying to use jQuery to fire an event when a css animation finishes and it's largely working, but for some reason the transitionend
event doesn't get called until I move my mouse off of the object in question.
Here's the method:
function replaceWithSearch(){
var searchWrapper = constructSearchBox("");
$(this).addClass("animated fadeOut"); // css animation
$(this).on('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend',
function (e){
console.log(e);
$(this).parent().replaceWith(searchWrapper);
if (document.URL.indexOf("search?s=") == -1){
document.getElementById("searchbox").focus();
}
});
}
It mostly seems to work with the exception that after the first css animation finishes, if I keep my mouse on the $(this)
element the transitionend
event won't fire. As soon as I move my mouse off of the element everything works perfectly.
I'm really at a loss with this one, any ideas? I'm using the css classes in animate.css.
I'm trying to use jQuery to fire an event when a css animation finishes and it's largely working, but for some reason the transitionend
event doesn't get called until I move my mouse off of the object in question.
Here's the method:
function replaceWithSearch(){
var searchWrapper = constructSearchBox("");
$(this).addClass("animated fadeOut"); // css animation
$(this).on('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend',
function (e){
console.log(e);
$(this).parent().replaceWith(searchWrapper);
if (document.URL.indexOf("search?s=") == -1){
document.getElementById("searchbox").focus();
}
});
}
It mostly seems to work with the exception that after the first css animation finishes, if I keep my mouse on the $(this)
element the transitionend
event won't fire. As soon as I move my mouse off of the element everything works perfectly.
I'm really at a loss with this one, any ideas? I'm using the css classes in animate.css.
Share Improve this question edited Jul 24, 2013 at 20:10 Mark Amery 155k90 gold badges429 silver badges470 bronze badges asked Jul 24, 2013 at 18:40 Slater VictoroffSlater Victoroff 21.9k23 gold badges91 silver badges148 bronze badges 01 Answer
Reset to default 12You're not getting a transitionend
event because you're not using CSS transitions; you're using CSS animations. The CSS of the animated
and fadeOut
classes in animate.css
is as follows:
.animated {
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
-o-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
}
.animated.fadeOut {
-webkit-animation-name: fadeOut;
-moz-animation-name: fadeOut;
-o-animation-name: fadeOut;
animation-name: fadeOut;
}
@-webkit-keyframes fadeOut {
0% {opacity: 1;}
100% {opacity: 0;}
}
@-moz-keyframes fadeOut {
0% {opacity: 1;}
100% {opacity: 0;}
}
@-o-keyframes fadeOut {
0% {opacity: 1;}
100% {opacity: 0;}
}
@keyframes fadeOut {
0% {opacity: 1;}
100% {opacity: 0;}
}
.animated.fadeOut {
-webkit-animation-name: fadeOut;
-moz-animation-name: fadeOut;
-o-animation-name: fadeOut;
animation-name: fadeOut;
}
That's not a CSS transition, it's a CSS animation. They trigger different events on pletion.
Replace this:
$(this).on('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend',
with this:
$(this).on('webkitAnimationEnd oanimationend oAnimationEnd msAnimationEnd animationend',
and I think everything should work fine.
The fact that something was happening when you moused off the $(this)
element is, I suspect, a coincidence; perhaps you have an entirely separate handler, like a mouseout
handler, with similar behavior that you're mistaking for the transitionend
handler, or perhaps you have some CSS transitions being applied on hover and one of those is triggering a transitionend
event pletely unrelated to the fadeOut?
本文标签: javascripttransitionend event doesn39t fire when my animation finishesStack Overflow
版权声明:本文标题:javascript - transitionend event doesn't fire when my animation finishes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741499547a2381993.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论