Check out a working example in CODEPEN, looking in to the link provided by Enkode.
Here I created a self-calling loop which can go as much as you specify, 100 in this case.
$(".clickButton").click(function() {
var counter = 0;
var timeDelay = 10; // in millisecond
var endCount= 100; // end of loop
(function loopFunc (counter) {
setTimeout(function () {
$("p").html(counter + "%");
if (counter++ < endCount) loopFunc(counter);
}, timeDelay)
})(1);
});
The loop will be invoked by clicking .clickButton
. Then a setTimeout
function create a pause inside of the loop iteration.
1
solved How can I add the animation “0 to a number”? jQuery