Execute complete function only once in jQuery animation?

前端 未结 5 2022
一向
一向 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 03:59

    You could just keep a flag, since they should animate simultaneously:

    var done = false;
    
    $("p").delay(500).animate({
        "font-size": "+=50"
    }, 1000, function() {
        if(!done) {
            done = true;
            alert("Done");
        }
    })​;
    

    Here's a demo.

提交回复
热议问题