I have an animation loop used to manipulate individual letters. It's wrapped in a timer in order to create a delayed offset. Each letter animates 100 ms later than the previous. I need to figure out how I can tell when the full animation is complete but I'm having some trouble because of the different types of nesting in use.
I've tried a few different things including trying to return a value from the animation, then the timer, and then the $.each function, but I'm sure this is off. I also was thinking I might be able to use the promise provided by jQuery's animate function, but not sure exactly how to implement this. Any advice here would be appreciated :] thank you
Here is my current code:
var offset = 200;
//drop individual letters down out of view
function dropLetters($letters){
var len = $letters.length - 1;
$letters.each(function(i){
var $letter = $(this);
setTimeout(function(){
$letter.animate({ top: offset + 'px' }, 300, function(){
if( i >= len ){
return $(this).promise();
}
});
}, 100 * i );
});
}
Edit: Sorry I realize I have omitted the offset variable. I added this back - it was just set to a value of 200.
Also, I realize this question is similar to another, but it also seems to differ from it. The answers provided here give a couple of different approaches that aren't present in the other question.