Jak Sprawdzić w jQuery, czy Element jest animowany?

Próbuję przenieść niektóre elementy na stronę, a podczas animacji chcę mieć "overflow:hidden" zastosowany do elemnt, a " overflow "z powrotem do" auto " po zakończeniu animacji.

Wiem, że jQuery ma funkcję użytkową, która określa, czy jakiś element jest animowany, ale nie mogę go znaleźć nigdzie w dokumentach

Author: James, 2009-04-07

5 answers

if( $(elem).is(':animated') ) {...}

Więcej informacji: http://docs.jquery.com/Selectors/animated


Lub:

$(elem)
    .css('overflow' ,'hidden')
    .animate({/*options*/}, function(){
        // Callback function
        $(this).css('overflow', 'auto');
    };
 193
Author: James,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-04-07 11:49:14

Alternatywnie, aby sprawdzić, czy coś nie jest animowane, możesz po prostu dodać "!":

if (!$(element).is(':animated')) {...}
 5
Author: Tim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-24 11:07:36

Jeśli chcesz zastosować css do animowanych elementów, możesz użyć pseudo selektora :animated i zrobić to w ten sposób,

$("selector").css('overflow','hidden');
$("selector:animated").css('overflow','auto');

Źródło: https://learn.jquery.com/using-jquery-core/selecting-elements/

 0
Author: Lucky,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-25 08:23:46
$('selector').click(function() {
  if ($(':animated').length) {
    return false;
  }

  $("html, body").scrollTop(0);
});
 0
Author: anand vishwakarma,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-26 13:30:03

Jeśli używasz animacji css i przypisujesz animację za pomocą określonego class name, możesz to sprawdzić w następujący sposób:

if($("#elem").hasClass("your_animation_class_name")) {}

Ale upewnij się, że usuwasz nazwę klasy, która obsługuje animację, po jej zakończeniu!

Ten kod może być użyty do usunięcia class name Po zakończeniu animacji:

$("#elem").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',
function(){ 
        $(this).removeClass("your_animation_class_name");
});
 -1
Author: KeepMove,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-22 22:20:02