JQuery Animate callback function does not work

I cannot use the following callback function. Warning never fires. The initial animation only runs on '. Carousel-images'.

$('.carousel-images').animate({'left' : left_indent},{queue:false, duration:500},function(){ alert("animate carousel"); //get the first list item and put it after the last list item $('.carousel-images li:last').after($('.carousel-images li:first')); //get the left indent to the default $('.carousel-images').css({'left' : '-1200px'}); }); 

Any help would be greatly appreciated!

+4
source share
2 answers

Since you are using the second method, the full callback should be passed as a property of the options object

You need to use

 $('.carousel-images').animate({'left' : left_indent},{queue:false, duration:500, complete: function(){ alert("animate carousel"); //get the first list item and put it after the last list item $('.carousel-images li:last').after($('.carousel-images li:first')); //get the left indent to the default $('.carousel-images').css({'left' : '-1200px'}); }}); 
+1
source

your syntex is wrong, it should be

 $('.carousel-images').animate({'left' : left_indent},{queue:false, duration:500, complete: function () { ... } }); 
0
source

Source: https://habr.com/ru/post/1494656/


All Articles