Shades88
Shades88

Reputation: 8360

Jquery Animate's callback function not working

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

Upvotes: 2

Views: 5956

Answers (4)

caesarsol
caesarsol

Reputation: 2113

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

Upvotes: 4

Mottie
Mottie

Reputation: 86403

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

Upvotes: 5

Asfour
Asfour

Reputation: 124

Maybe you have to call jquery in this way

$(document).ready(function(){

   // your code;

});

Upvotes: 1

dku.rajkumar
dku.rajkumar

Reputation: 18568

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/

Upvotes: 5

Related Questions