datamad2017/js/jquery.countTo.min.js

1 line
928 B
JavaScript
Raw Normal View History

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