You can create custom .queue() to avoid unlimited nesting.
var q = $({}); function animToQueue(theQueue, selector, animationprops) { theQueue.queue(function(next) { $(selector).animate(animationprops, next); }); } // usage animToQueue(q, '#first', {width: '+=100'}); animToQueue(q, '#second', {height: '+=100'}); animToQueue(q, '#second', {width: '-=50'}); animToQueue(q, '#first', {height: '-=50'});
Demo at http://jsfiddle.net/gaby/qDbRm/2/
If, on the other hand, you want to perform the same animation for multiple elements one by one, you can use their index for .delay() each element of the animation throughout all the previous ones.
$('li.some').each(function(idx){ var duration = 500; $(this).delay(duration*idx).animate({ width: '+=100' }, duration); });
Demo at http://jsfiddle.net/gaby/qDbRm/3/
source share