user2593040 user2593040 - 1 month ago 12
jQuery Question

How do I repeat JQuery Counter when timer finished

I have found a great counter script but on one of the scripts I need it to repeat after the counting has reached 999. What would I add to make it repeat when finished counting?

jQuery_2_2_4('#count-five').jQuerySimpleCounter({
start : 0,
end : 999,
// easing effect
easing : 'linear',
// duration time in ms
duration : 100000
});

Answer

The counter plugin exposes a complete callback. If you want it to repeat, run the same commands in the complete function. Here's one way to do it:

function repeatCounter() {
    jQuery_2_2_4('#count-five').jQuerySimpleCounter({
        start : 0,
        end : 999,
        // easing effect
        easing : 'linear',
        // duration time in ms
        duration : 100000,
        complete: repeatCounter
    });
}

repeatCounter();
Comments