admin管理员组文章数量:1134605
I'm trying to move some elements on the page, and during the time the animation occurs, I want to have "overflow:hidden" applied to an elemnt, and "overflow" back to "auto" once the animation is completed.
I know jQuery has an utility function that determines whether some element is being animated but I can't find it anywhere in the docs
I'm trying to move some elements on the page, and during the time the animation occurs, I want to have "overflow:hidden" applied to an elemnt, and "overflow" back to "auto" once the animation is completed.
I know jQuery has an utility function that determines whether some element is being animated but I can't find it anywhere in the docs
Share Improve this question asked Apr 7, 2009 at 10:03 RaduRadu 05 Answers
Reset to default 204if( $(elem).is(':animated') ) {...}
More info: https://api.jquery.com/animated-selector/
Or:
$(elem)
.css('overflow' ,'hidden')
.animate({/*options*/}, function(){
// Callback function
$(this).css('overflow', 'auto');
};
Alternatively, to test if something is not animated, you can simply add a "!":
if (!$(element).is(':animated')) {...}
if you are using css
animation and assign the animation by using specific class name
, then you can check it like this:
if($("#elem").hasClass("your_animation_class_name")) {}
But make sure that you are removing the class namewhich is handling the animation, after the animation is finished!
This code can be used to remove the class name
after the animation is finished:
$("#elem").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',
function(){
$(this).removeClass("your_animation_class_name");
});
If you want to apply css to animated elements, you can use the :animated
pseudo selector and do it like this,
$("selector").css('overflow','hidden');
$("selector:animated").css('overflow','auto');
source : https://learn.jquery.com/using-jquery-core/selecting-elements/
$('selector').click(function() {
if ($(':animated').length) {
return false;
}
$("html, body").scrollTop(0);
});
本文标签: javascriptHow do I find out with jQuery if an element is being animatedStack Overflow
版权声明:本文标题:javascript - How do I find out with jQuery if an element is being animated? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736861544a1955935.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论