hugh jackson
hugh jackson

Reputation: 43

anonymous callback function in .animate() not working

I can't for the life of me figure out what the problem with this code is. The animation itself works fine:

if (!list.is(':animated')) {
    list.animate(
        {"top": "+="+item_size},
        {queue:false, duration:speed},
        function() {
            alert();
        }
    ); // end of animate function

} //end of if statement

Upvotes: 4

Views: 3477

Answers (2)

mdrg
mdrg

Reputation: 3402

Check the API, you don't seem to be calling the function right:

.animate( properties, [ duration ], [ easing ], [ callback ] )

Guess this is how you should call it:

.animate( {"top": "+="+item_size}, speed, 'linear', function(){alert();});

Change linear to whatever easing function you need.

Upvotes: 1

lonesomeday
lonesomeday

Reputation: 237817

You're mixing up the two signatures of .animate(). You need to make the callback a part of the options argument:

if(!list.is(':animated')){
    list.animate({
        top: "+="+item_size
    }, //end of properties argument
    {
        queue: false, 
        duration: speed,
        complete: function(){
            alert();
        } //end of callback
    }  // end of options argument
    ); // end of animate function
} //end of if statement

Upvotes: 5

Related Questions