I am trying to make a sequential animation, where a loop iterates through a list of elements .post‘s and fades them in slow. The difficult part is having it so that the next iteration begins fading in before the last one has finished fading. All I have so far is a simple sequential animator that fades them in one after the other.
$(".post").hide();
var posts = $(".post"),
i = 0;
(function() {
$(posts[i++]).fadeIn('slow', arguments.callee);
})();
Does anyone know how I could change this to allow .post to fadeIn() before the previous elem/s have finished?
Iterate over them using
each()and use asetTimeout()for each one, multiplying the duration of the animation by the currentindexin the each.So each
setTimeout()will have a duration ofn*600, which should give you the effect you want.By the way, if you don’t need the
postsvariable for any other purpose, you can eliminate it and chain the.each()after the.hide(), as in$(".post").hide().each(func...)EDIT: I had an error. I was using
thisinside thesetTimeout()which has a different value. Edited to pass in the correct value.EDIT: Mis-read the question. Changed the duration of
setTimeout()to300to give a partial overlap in the animations.