I would like to animate different DIVs sequentially. Is there a way to force JQuery to process its queue in the middle of my code? Something like:
for (var i = 0; i < myHugeNumber; i++){
var divName = '#Div' + i;
$(divName).animate({"left": "-=50px"}, "slow");
$.ProcessQueue() // Once finished animating, continue with FOR loop.
}
I am fully aware that you can pass a callback to the .animate
function and this can be achieved with some recursive voodoo, howev开发者_StackOverflower this would require a lot of retooling in my code. And I'm a stubborn, stubborn man. Is there a quick and dirty method to force JQuery to process its queue on-the-fly?
I know this uses the callback, but the code seems simpler than the for loop. I thought I would throw it out there.
var maxI = myHugeNumber;
var curI = 0;
startAnimation();
function startAnimation(){
var id = '#Div' + curI;
$(id).animate({'left': '-=50px'}, 'slow', function(){
curI++;
if(curI<maxI){
startAnimation();
}
});
}
精彩评论