jQuery count up all

by jack_pallot

HTML

<h2 class="clients"></h2>
<h2 class="services"></h2>
<h2 class="years"></h2>

JavaScript

! function (a) {
    a.fn.countTo = function (b) {
        b = a.extend({}, a.fn.countTo.defaults, b || {});
        var c = Math.ceil(b.speed / b.refreshInterval),
            d = (b.to - b.from) / c;
        return a(this).each(function () {
            function i() {
                setTimeout(function(){
                g += d, f++, a(e).html(g.toFixed(b.decimals)), "function" == typeof b.onUpdate && b.onUpdate.call(e, g), f >= c && (clearInterval(h), g = b.to, "function" == typeof b.onComplete && b.onComplete.call(e, g))},3000);
            }
            var e = this,
                f = 0,
                g = b.from,
                h = setInterval(i, b.refreshInterval)
        })
    }, a.fn.countTo.defaults = {
        from: 0,
        to: 10,
        speed: 1e3,
        refreshInterval: 10,
        decimals: 0,
        onUpdate: null,
        onComplete: null
    }
}(jQuery);

jQuery(function($) {
    $('.clients').countTo({
        from: 0,
        to: 10,
        speed: 1300
    });
    $('.services').countTo({
        from: 0,
        to: 10,
        speed: 1300
    });
    $('.years').countTo({
        from: 0,
        to: 10,
        speed: 1300
    });
});