Execute complete function only once in jQuery animation?

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

    This code can be used as a generic 'countdown' type of function.

    // Function that returns a function,
    // which when invoked 'count' number of times,
    // will invoke the function 'fn'
    function runOnZero (count, fn) {
        return function () {
            if (--count <= 0) {
                fn();
            }
        };
    }
    
    // Get all the 

    s var ps = $("p"); // Do your thing after ps.length calls var whenAllDone = runOnZero(ps.length, function () { alert("Done"); }); ps.delay(500).animate({ "font-size": "+=50" }, 1000, whenAllDone)​;

提交回复
热议问题