How do I find out with jQuery if an element is bei

2019-01-04 01:13发布

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

5条回答
我想做一个坏孩纸
2楼-- · 2019-01-04 01:42

Alternatively, to test if something is not animated, you can simply add a "!":

if (!$(element).is(':animated')) {...}
查看更多
一纸荒年 Trace。
3楼-- · 2019-01-04 01:50

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");
});
查看更多
你好瞎i
4楼-- · 2019-01-04 01:52
if( $(elem).is(':animated') ) {...}

More info: http://docs.jquery.com/Selectors/animated


Or:

$(elem)
    .css('overflow' ,'hidden')
    .animate({/*options*/}, function(){
        // Callback function
        $(this).css('overflow', 'auto');
    };
查看更多
该账号已被封号
5楼-- · 2019-01-04 01:53

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/

查看更多
forever°为你锁心
6楼-- · 2019-01-04 01:53
$('selector').click(function() {
  if ($(':animated').length) {
    return false;
  }

  $("html, body").scrollTop(0);
});
查看更多
登录 后发表回答