Skip to content

Instantly share code, notes, and snippets.

@umidjons
Created March 25, 2014 05:37
Show Gist options
  • Save umidjons/9755797 to your computer and use it in GitHub Desktop.
Save umidjons/9755797 to your computer and use it in GitHub Desktop.
jQuery: animate elements one after another

Animate elements one by one

We have these divs with .a class.

<div class="a b">d</div>    
<div class="a c">d</div>    
<div class="a d">d</div>    
<div class="a e">d</div>    
<div class="a f">d</div>    
<div class="a g">d</div>    
<div class="a h">d</div>    
<div class="a i">d</div>    
<div class="a j">d</div>    
<div class="a k">d</div>    
<div class="a l">d</div>    
<div class="a m">d</div>    

We want animate them one after another.

// start animation
nextAnim($('.a'));

function nextAnim(elems)
{
	// if we have element, animate it
	elems.eq(0).animate({'left': 50}, function()
	{
		nextAnim(elems.slice(1));  // slice off the first element
	});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment