Execute complete function only once in jQuery animation?

前端 未结 5 1971
一向
一向 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:54

    var $p = $("p");
    var lastIndex = $p.length - 1;
    
    $p.delay(500).animate({
        "font-size": "+=50"
    }, 1000, function() {
        if ($p.index($(this)) == lastIndex) {
            alert("Done");
        }
    })
    

    Demo

提交回复
热议问题