Anonymous callback function in .animate () does not work

I can’t understand in life that there is a problem with this code. The animation itself works great:

if (!list.is(':animated')) { list.animate( {"top": "+="+item_size}, {queue:false, duration:speed}, function() { alert(); } ); // end of animate function } //end of if statement 
+4
source share
2 answers

You are mixing two .animate() signatures. You should make the callback part of the options argument:

 if(!list.is(':animated')){ list.animate({ top: "+="+item_size }, //end of properties argument { queue: false, duration: speed, complete: function(){ alert(); } //end of callback } // end of options argument ); // end of animate function } //end of if statement 
+5
source

Check the API , you don't seem to be calling the function correctly:

 .animate( properties, [ duration ], [ easing ], [ callback ] ) 

Guess what you call it:

 .animate( {"top": "+="+item_size}, speed, 'linear', function(){alert();}); 

Change linear to any attenuation function you need.

+1
source

All Articles