Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animate's callback function (complete) executed at start?

Tags:

jquery

I'm using jQuery 1.5.1 This is my code:

$('.cellcontent').animate({    left: '-=190'}, {    easing: alert('start ani'),    duration: 5000,    complete: alert('end ani')}); 

I get both alerts before the animation starts!? I want the complete function to start after the animation has ended. Any thoughts?

like image 453
Overbeeke Avatar asked Mar 22 '11 20:03

Overbeeke


People also ask

What is callback in jQuery?

A function to be executed after the animation completes. To learn more about callback, please read our jQuery Callback chapter Required. Specifies one or more CSS properties/values to animate (See possible values above) Optional. Specifies additional options for the animation. Possible values:

Why does complete call a function when finished?

Since complete expects a function, it executes the code you pass to it to get a function object that it can call back to when finished. Show activity on this post. Best solution is this.

What is the use of the animate () method?

The animate() method performs a custom animation of a set of CSS properties. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect. Only numeric values can be animated (like "margin:30px").

Is complete a function or an activity?

And complete should be a function. Show activity on this post. You need to pass a function to complete. Since complete expects a function, it executes the code you pass to it to get a function object that it can call back to when finished. Show activity on this post. Best solution is this.


1 Answers

You need to pass a function to call. Instead you are calling the function.

complete:  function() { alert('end ani'); }  
like image 163
Bradford Avatar answered Oct 06 '22 01:10

Bradford