Run
Run

Reputation: 57256

jQuery animate callback is not triggered after queue:false has been used?

Why the animate callback is not triggered after queue:false has been used?

For instance, a callback occurs here.

$("#move").click(function(){

        $(".box").animate({ 
            marginLeft: "100px"
        },500 , function() {

            alert('complete');
            console.log('complete');
        });

        return false;
});

but not with this,

$("#move").click(function(){

        $(".box").animate({ 
            marginLeft: "100px"
        }, { queue:false, duration:500 } , function() {

            alert('complete');
            console.log('complete');
        });

        return false;
});

the link to jsfiddle

Can I have both queue:false and callback at the same time?

Upvotes: 2

Views: 1786

Answers (2)

Tomer Almog
Tomer Almog

Reputation: 3868

That will not work karthikr... the queue will not function anymore. as you mentioned animate is defined as .animate( properties, options ).You need to make the callback a part of the options argument:

$("#move").click(function(){

    $(".box").animate({ 
        marginLeft: "100px",
     },{queue:false, duration:500, complete:function() {

          alert('complete');
          console.log('complete');
        }//callback function
    });//options and animate

    return false;
});

Upvotes: 6

karthikr
karthikr

Reputation: 99660

The format is wrong:

Checkout this fiddle

The jquery animate is defined as follows: .animate( properties, options )

$("#move").click(function(){

        $(".box").animate({ 
            marginLeft: "100px",
         queue:false, duration:500 } , 5000, function() {

            alert('complete');
            console.log('complete');
        });

        return false;
});

Upvotes: 2

Related Questions