Jquery Animate's callback function not working

亡梦爱人 提交于 2021-01-27 20:19:24

问题


I have a jQuery animate function. A need to execute a function as soon as animation ends. So gotta use callback function. So I tried it. Didn't work, I thought there must be problem in that particular function so I reduced it to simply this...

phGrp.animate({bottom:0},
              {duration: 1500, easing: 'swing'}, 
              function(){alert('hello')}
);

Animation works correctly, no error, but callback won't execute. What can be the problem? I saw a solution of using anonymous function. So I have used it, but still problem persists.

Please help


回答1:


try something like below, check the fiddle it is working

 phGrp.animate({bottom:0},1500,'swing', 
          function(){alert('hello');
         }
 );

fiddle : http://jsfiddle.net/hYtuP/

for refrence check the link : http://api.jquery.com/animate/




回答2:


The problem is that the callback function needs to be inside with options

.animate( properties, options ) (ref, options = duration, easing, complete, etc)

phGrp.animate(
{
  bottom:0
},
{
  duration : 1500,
  easing   : 'swing',
  complete : function(){ alert('hello') }
});



回答3:


also, make sure you don't have any transition rule in the CSS, it made me crazy!




回答4:


Maybe you have to call jquery in this way

$(document).ready(function(){

   // your code;

});


来源:https://stackoverflow.com/questions/8603823/jquery-animates-callback-function-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!