Execute complete function only once in jQuery animation?

前端 未结 5 1970
一向
一向 2021-01-24 03:08

I\'m trying to animate the font size of some text:

$(\"p\").delay(500).animate({
    \"font-size\": \"+=50\"
}, 1000, function() {
    alert(\"Done\");
})​;
         


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 04:05

    Just to notice, you can also use a promise object:

    Return a Promise object to observe when all actions of a certain type bound to the collection, queued or not, have finished.

    First example (demo):

    $("p").delay(500).animate({
        "font-size": "+=50"
    }, 1000).promise().done(function(){
        alert("done");
    });​
    

    Second example (demo):

    $.when($("p").delay(500).animate({
        "font-size": "+=50"
    }, 1000)).done(function(){
        alert("done");
    });​
    

提交回复
热议问题