Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.done after .animate callback function

Tags:

jquery

I want call a function after .animate callback function. I am using .done method for this purpose but it is not working. fiddle

$(function(){
$('button').click(function(){
$('div').animate({width:'400px'},300,function(){alert(0)})
}).promise().done(function(){alert(1)})
})
like image 861
Jitender Avatar asked Oct 14 '13 11:10

Jitender


2 Answers

You were calling the done on the button element, not on the div which is animated

$('button').click(function () {
    $('div').animate({
        width: '400px'
    }, 300, function () {
        alert(0)
    }).promise().done(function () {
        alert(1)
    })
})

Demo: Fiddle

like image 196
Arun P Johny Avatar answered Sep 29 '22 03:09

Arun P Johny


You need to put the promise on the animate function. At the minute, you have it on the .click:

$('button').click(function(){
    $('div').animate({width:'400px'},300,function(){alert(0)})
            .promise()
            .done(function(){alert("1")});
})
like image 21
CodingIntrigue Avatar answered Sep 29 '22 04:09

CodingIntrigue