|
- (function(e){e.fn.countTo=function(n){return n=n||{},e(this).each(function(){var t=e.extend({},e.fn.countTo.defaults,{from:e(this).data("from"),to:e(this).data("to"),speed:e(this).data("speed"),refreshInterval:e(this).data("refresh-interval"),decimals:e(this).data("decimals")},n),f=Math.ceil(t.speed/t.refreshInterval),d=(t.to-t.from)/f,l=this,o=e(this),i=0,a=t.from,r=o.data("countTo")||{};o.data("countTo",r),r.interval&&clearInterval(r.interval),r.interval=setInterval(u,t.refreshInterval),s(a);function u(){a+=d,i++,s(a),typeof t.onUpdate=="function"&&t.onUpdate.call(l,a),i>=f&&(o.removeData("countTo"),clearInterval(r.interval),a=t.to,typeof t.onComplete=="function"&&t.onComplete.call(l,a))}function s(m){var v=t.formatter.call(l,m,t);o.text(v)}})},e.fn.countTo.defaults={from:0,to:0,speed:1e3,refreshInterval:100,decimals:0,formatter:c,onUpdate:null,onComplete:null};function c(n,t){return n.toFixed(t.decimals)}})(jQuery);
|