I'm trying to create an animation sequence with jQuery where one animation starts after the previous one is done. But I just can't wrap my head around it. I've tried to make use of the jQuery.queue, but I don't think I can use that because it seems to have one individual queue for each element in the jQuery array.
I need something like:
$('li.some').each(function(){
// Add to queue
$(this).animate({ width: '+=100' }, 'fast', function(){
// Remove from queue
// Start next animation
});
});
Is there a jQuery way to do this or do I have to write and handle my own queue manually?
The callback of .animate() actually accepts another .animate(), so all you would have to do would be
and so on.
why not build up a queue?
EDIT: added speed param
You could call the next one recursively.
Thanks to everybody replying!
I thought I should share the outcome of my question. Here is a simple jQuery slideDownAll plugin that slides down one item at a time rather than all at once.
Not very well test, but anyways.
Enjoy!!
You can make a custom
.queue()
to avoid the limitless nesting..Demo at http://jsfiddle.net/gaby/qDbRm/2/
If, on the other hand, you want to perform the same animation for a multitude of elements one after the other then you can use their index to
.delay()
each element's animation for the duration of all the previous ones..Demo at http://jsfiddle.net/gaby/qDbRm/3/