开发者

jquery animate in sequence without callback function

开发者 https://www.devze.com 2023-03-25 16:12 出处:网络
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:

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();
      }
   });
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号