// (function($){ // $.fn.numberRock=function(options){ // var defaults={ // speed:24, // count:100 // }; // var opts=$.extend({}, defaults, options); // var div_by = 100, // count=opts["count"], // speed = Math.floor(count / div_by), // sum=0, // $display = this, // run_count = 1, // int_speed = opts["speed"]; // var int = setInterval(function () { // if (run_count <= div_by&&speed!=0) { // $display.text(sum=speed * run_count); // run_count++; // } else if (sum < count) { // $display.text(++sum); // } else { // clearInterval(int); // } // }, int_speed); // } // })(jQuery); //绐楀彛鏄剧ず鎵嶅姞杞 var wrapTop = $(".digital").offset().top; var istrue = true; $(window).on("scroll",function () { var s = $(window).scrollTop(); // console.log(wrapTop - 500) // console.log(s) if (s > wrapTop - 700 && istrue) { $(".timer").each(count); function count(a) { var b = $(this); a = $.extend({}, a || {}, b.data("countToOptions") || {}); b.countTo(a) }; istrue = false; }; }) //璁剧疆璁℃暟 $.fn.countTo = function (options) { options = options || {}; return $(this).each(function () { //褰撳墠鍏冪礌鐨勯€夐」 var settings = $.extend({}, $.fn.countTo.defaults, { from: $(this).data('from'), to: $(this).data('to'), speed: $(this).data('speed'), refreshInterval: $(this).data('refresh-interval'), decimals: $(this).data('decimals') }, options); //鏇存柊鍊 var loops = Math.ceil(settings.speed / settings.refreshInterval), increment = (settings.to - settings.from) / loops; //鏇存敼搴旂敤鍜屽彉閲 var self = this, $self = $(this), loopCount = 0, value = settings.from, data = $self.data('countTo') || {}; $self.data('countTo', data); //濡傛灉鏈夐棿鏂紝鎵惧埌骞舵竻闄 if (data.interval) { clearInterval(data.interval); }; data.interval = setInterval(updateTimer, settings.refreshInterval); //鍒濆鍖栬捣濮嬪€ render(value); function updateTimer() { value += increment; loopCount++; render(value); if (typeof (settings.onUpdate) == 'function') { settings.onUpdate.call(self, value); } if (loopCount >= loops) { //绉诲嚭闂撮殧 $self.removeData('countTo'); clearInterval(data.interval); value = settings.to; if (typeof (settings.onComplete) == 'function') { settings.onComplete.call(self, value); } } } function render(value) { var formattedValue = settings.formatter.call(self, value, settings); $self.html(formattedValue); } }); }; $.fn.countTo.defaults = { from: 0, //鏁板瓧寮€濮嬬殑鍊 to: 0, //鏁板瓧缁撴潫鐨勫€ speed: 1000, //璁剧疆姝ラ暱鐨勬椂闂 refreshInterval: 100, //闅旈棿鍊 decimals: 0, //鏄剧ず灏忎綅鏁 formatter: formatter, //娓叉煋涔嬪墠鏍煎紡鍖 onUpdate: null, //姣忔鏇存柊鍓嶇殑鍥炶皟鏂规硶 onComplete: null //瀹屾垚鏇存柊鐨勫洖璋冩柟娉 }; function formatter(value, settings) { return value.toFixed(settings.decimals); } //鑷畾涔夋牸寮 $('#count-number').data('countToOptions', { formmatter: function (value, options) { return value.toFixed(options.decimals).replace(/\B(?=(?:\d{3})+(?!\d))/g, ','); } }); //瀹氭椂鍣 $('.timer').each(count); function count(options) { var $this = $(this); options = $.extend({}, options || {}, $this.data('countToOptions') || {}); $this.countTo(options); }