jQuery wait till all page animations are done

I know how to wait till an animation is done with

$('#element').animate(speed,function(){
//code here
});

and with multiple elements with

$('#element1, #element2').promise().done(function(){
//code here
});

but how do I wait till all of the elements on the page are done animating? I would much rather not just put in every element that I'm waiting for in there.

Answers


To select everything that's being animated currently, just do $(":animated") http://api.jquery.com/animated-selector/

Combining that with what you already have there, it'd just be

$(":animated").promise().done(function() {
    //code here
});

The answer given by Jeremy T works fine - although based on the comments on the jquery site he linked (http://api.jquery.com/animated-selector/), it would be a faster solution to add a class to each element on the page that may be animated, and then select them using

    $('.animationclass').filter(':animated').promise().done(function() {
//Your function
});

Need Your Help

How to include a PHP variable inside a MySQL insert statement

php mysql variables insert

I'm trying to insert values in the contents table. It works fine if I do not have a PHP variable inside VALUES. When I put the variable $type inside VALUES then this doesn't work. What am I doing w...

Accessing dates in PHP beyond 2038

php date time timestamp year2038

I am of of the understanding that due to the nature that PHP represents dates using milliseconds, you cannot represent dates past 2038. I have a problem where I want to calculate dates far in the ...