How do I find out with jQuery if an element is being 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");
});

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

if (!$(element).is(':animated')) {...}

if( $(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');
    };