2

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

0

4 Answers 4

5

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/

Sign up to request clarification or add additional context in comments.

5 Comments

how stupid of me!! Was just missing a semicolon. But if I was, how did I not get any error !
nope you were not just missing semicolon, you have also given duration and easing as hash options as second arguments although animate takes it as second and third arguments separately.
oh is it .. thats good then this is additional info for me.. thanks
hehe, no problem. u really checked my line of code. it worked right?
ohhh. then some weird mistake. Nonetheless, I used your solution only.
5

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') }
});

1 Comment

Your reference just ended my hours long search as to why I was having this problem. And It taught me a lot about how JQueries documentation is formatted
4

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

Comments

1

Maybe you have to call jquery in this way

$(document).ready(function(){

   // your code;

});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.