Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct syntax for jQuery animate "complete" callback

I have to use a callback function when a jQuery animation is complete. I've always did that like this:

.animate({ properties }, duration, function() { /* callback */ });

However, when asking a question here I've been proposed a solution with a different syntax.

$('#redirectNoticeContainer').animate({ properties }, { queue: false, duration: 123 });

where am I supposed to put the callback function there? This is my guess, but it is not working.

$('#redirectNoticeContainer').animate({ properties }, { queue: false, duration: 123 }, function () {
console.log("ok");
setTimeout(function () { window.location.replace("/Account/Login"); }, 1200);
});

The animation works. Callback doesn't. Where should I put it?

like image 389
Saturnix Avatar asked Nov 30 '22 01:11

Saturnix


1 Answers

That form of animate() takes a complete option:

$("#redirectNoticeContainer").animate({
    // properties...
}, {
    queue: false,
    duration: 123,
    complete: function() {
        console.log("ok");
        setTimeout(function() {
            window.location.replace("/Account/Login");
        }, 1200);
    }
});
like image 62
Frédéric Hamidi Avatar answered Dec 19 '22 06:12

Frédéric Hamidi