How to wait for the end of the elements' current animations?
Compact syntax with timing methods:
1
$('.some').join().doSome().jQueryStuff();
The join() method also provides parameters for selecting the queue or to wait for an empty queue instead of the current animations' end.
Compare this to the old way with more syntactic fluff:
1
2
3
4
5
6
7
8
9
10
11
var waiting = $('.some').length;
if (!waiting) {
$('.some').doSome().jQueryStuff();
} else {
$('.some').queue(function(next){
next();
if (!--waiting) {
$('.some').doSome().jQueryStuff();
}
});
}
Similar patterns with animations
- How to
wait for the elements' animation queues to get empty?$('.some').wait().doSome().jQueryStuff();
- How to
wait for the end of the elements' current animations for a given queue name?$('.some').join(queue).doSome().jQueryStuff();
- How to
wait for the elements' animation queues to get empty with .join()?$('.some').join(true).doSome().jQueryStuff();
- How to
wait for the elements' animation queues for a given queue name to get empty?$('.some').join(queue,true).doSome().jQueryStuff();
- How to
queue an animation and return immediately?$('.some').animate(attributes,options);
- How to
queue an animation for a single element and wait until it finished?$('#single').animate(attributes,options,$).jQueryStuff();
- How to
queue an animation for multiple elements and wait until they finished?$('.many').animate(attributes,options,$).jQueryStuff();