1//çªå£æ¾ç¤ºæå è½½ 2 var wrapTop = $(".c-timer").offset().top; 3 var istrue = true; 4 $(window).on("scroll", 5 function() { 6 var s = $(window).scrollTop(); 7 if (s > wrapTop - 500 && istrue) { 8 $(".timer").each(count); 9 function count(a) { 10 var b = $(this); 11 a = $.extend({}, 12 a || {}, 13 b.data("countToOptions") || {}); 14 b.countTo(a) 15 }; 16 istrue = false; 17 }; 18 }) 19 //è®¾ç½®è®¡æ° 20 $.fn.countTo = function (options) { 21 options = options || {}; 22 return $(this).each(function () { 23 //å½åå ç´ çé项 24 var settings = $.extend({}, $.fn.countTo.defaults, { 25 from: $(this).data('from'), 26 to: $(this).data('to'), 27 speed: $(this).data('speed'), 28 refreshInterval: $(this).data('refresh-interval'), 29 decimals: $(this).data('decimals') 30 }, options); 31 //æ´æ°å¼ 32 var loops = Math.ceil(settings.speed / settings.refreshInterval), 33 increment = (settings.to - settings.from) / loops; 34 //æ´æ¹åºç¨ååé 35 var self = this, 36 $self = $(this), 37 loopCount = 0, 38 value = settings.from, 39 data = $self.data('countTo') || {}; 40 $self.data('countTo', data); 41 //妿æé´æï¼æ¾å°å¹¶æ¸ é¤ 42 if (data.interval) { 43 clearInterval(data.interval); 44 }; 45 data.interval = setInterval(updateTimer, settings.refreshInterval); 46 //åå§åèµ·å§å¼ 47 render(value); 48 function updateTimer() { 49 value += increment; 50 loopCount++; 51 render(value);
52 if (typeof(settings.onUpdate) == 'function') { 53 settings.onUpdate.call(self, value); 54 } 55 if (loopCount >= loops) { 56 //ç§»åºé´é 57 $self.removeData('countTo'); 58 clearInterval(data.interval); 59 value = settings.to; 60 if (typeof(settings.onComplete) == 'function') { 61 settings.onComplete.call(self, value); 62 } 63 } 64 } 65 function render(value) { 66 var formattedValue = settings.formatter.call(self, value, settings); 67 $self.html(formattedValue); 68 } 69 }); 70 }; 71 $.fn.countTo.defaults={ 72 from:0, //æ°åå¼å§çå¼ 73 to:0, //æ°åç»æçå¼ 74 speed:1000, //设置æ¥é¿çæ¶é´ 75 refreshInterval:100, //éé´å¼ 76 decimals:0, //æ¾ç¤ºå°ä½æ° 77 formatter: formatter, //渲æä¹åæ ¼å¼å 78 onUpdate:null, //æ¯æ¬¡æ´æ°åçåè°æ¹æ³ 79 onComplete:null //å®ææ´æ°çåè°æ¹æ³ 80 }; 81 function formatter(value, settings){ 82 return value.toFixed(settings.decimals); 83 } 84 //èªå®ä¹æ ¼å¼ 85 $('#count-number').data('countToOptions',{ 86 formmatter:function(value, options){ 87 return value.toFixed(options.decimals).replace(/\B(?=(?:\d{3})+(?!\d))/g, ','); 88 } 89 }); 90 //宿¶å¨ 91 $('.timer').each(count); 92 function count(options){ 93 var $this=$(this); 94 options=$.extend({}, options||{}, $this.data('countToOptions')||{}); 95 $this.countTo(options); 96 }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.