jquery(document).ready(function($) { $.fn.countto = function(a) { a = a || {}; return $(this).each(function() { var c = $.extend({}, $.fn.countto.defaults, { from: $(this).data("from"), to: $(this).text(), speed: 8000, refreshinterval: $(this).data("refresh-interval"), decimals: $(this).data("decimals") }, a); var h = math.ceil(c.speed / c.refreshinterval), i = (c.to - c.from) / h; var j = this, f = $(this), e = 0, g = c.from, d = f.data("countto") || {}; f.data("countto", d); if (d.interval) { clearinterval(d.interval) } d.interval = setinterval(k, c.refreshinterval); b(g); function k() { g += i; e++; b(g); if (typeof(c.onupdate) == "function") { c.onupdate.call(j, g) } if (e >= h) { f.removedata("countto"); clearinterval(d.interval); g = c.to; if (typeof(c.oncomplete) == "function") { c.oncomplete.call(j, g) } } } function b(m) { var l = c.formatter.call(j, m, c); f.html(l) } }) }; $.fn.countto.defaults = { from: 0, to: 0, speed: 1000, refreshinterval: 100, decimals: 0, formatter: formatter, onupdate: null, oncomplete: null }; function formatter(b, a) { return b.tofixed(); } $(".timer").data("counttooptions", { formatter: function(b, a) { return b.tofixed().replace(/\b(?=(?:\d{3})+(?!\d))/g, ","); } }); $(".timer").each(count); function count(a) { var b = $(this); a = $.extend({}, a || {}, b.data("counttooptions") || {}); b.countto(a) }; });