jquery deffered with a random number of animations -


I found x the number of animations that run on a random timer. I also have a code that needs to be run after all the animation is completed.

I had thought of using deferred, but it does not seem that the way I thought it was going on. There is a link here (you may need to run it for a while to work):

Code:

  var callback = Function () {Warning ('done!'); }; Var Animation; (Var i = 0; i & lt; $ ('div'). Length; i ++) {var random = Math.random () * (800 - 100) + 100; Animation = $ ('div'). Eq (i) .slideUp (random); } $ When (animation) .done (callback);   

Any suggestions about waiting for a callback once all animation is complete?

You are always overriding the animation variable. So the object you $ Send in will be one of the last repetition.

Add them to an array and $ When calling from that array:

  var animation = []; (Var i = 0; i & lt; $ ('div'). Length; i ++) {var random = Math.random () * (800 - 100) + 100; Animations.push (. $ ('Div') eq (i) .slideUp (random)); } $ when. Apple ($, animation). Don (callback);   

Reference:

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -