I have something like the following code
for(i=0, j=10; i<j ; i++){
$('#an-element-'+i).fadeIn();
}
How do I make it so that each iteration in the loop will only start once the fadeIn(); animation has completed?
edit---sorry my bad I had not included the 'i' in the loop
for
loops are synchronous, but animations are asynchronous. You'll need to use recursion.
var i = 0, j = 10;
(function fadeNext () {
if (i < j) {
$('#an-element-' + i++).fadeIn(fadeNext);
}
}) ();
http://jsfiddle.net/uq9mH/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With