1// æ°åå¨ç»æä»¶ 2(function($) { 3 $.fn.countUp = function(options) { 4 var settings = $.extend({ 5 duration: 2000, 6 easing: 'swing', 7 decimals: 0, 8 prefix: '', 9 suffix: '', 10 useCommas: false // æ·»å æ¯å¦ä½¿ç¨ååä½åé符çé项 11 }, options); 12 13 return this.each(function() { 14 var $this = $(this); 15 var countTo = $this.attr('data-count'); 16 17 if (!countTo) return; 18 19 var decimals = settings.decimals; 20 var decimalFactor = Math.pow(10, decimals); 21 22 $({countNum: 0}).animate({countNum: parseFloat(countTo.replace(/,/g, ''))}, { 23 duration: settings.duration, 24 easing: settings.easing, 25 step: function() { 26 requestAnimationFrame(function() { 27 var nums = Math.round(this.countNum * decimalFactor) / decimalFactor; 28 if (decimals > 0) { 29 nums = nums.toFixed(decimals); 30 } else { 31 nums = Math.round(nums); 32 } 33 // æ ¹æ®è®¾ç½®å³å®æ¯å¦æ·»å ååä½åé符 34 if (settings.useCommas) { 35 nums = formatNumberWithCommas(nums); 36 } 37 $this.text(settings.prefix + nums + settings.suffix); 38 }.bind(this)); 39 }, 40 complete: function() { 41 requestAnimationFrame(function() { 42 var nums = Math.round(this.countNum * decimalFactor) / decimalFactor; 43 if (decimals > 0) { 44 nums = nums.toFixed(decimals); 45 } else { 46 nums = Math.round(nums); 47 } 48 // æ ¹æ®è®¾ç½®å³å®æ¯å¦æ·»å ååä½åé符 49 if (settings.useCommas) { 50 nums = formatNumberWithCommas(nums); 51 } 52 $this.text(settings.prefix + nums + settings.suffix); 53 }.bind(this)); 54 } 55 }); 56 }); 57 }; 58})(jQuery); 59 60// åå§åæ°åå¨ç» 61$(document).ready(function() { 62 // æ£æ¥å ç´ æ¯å¦å¨è§å£ä¸ 63 function isElementInViewport(el) { 64 var rect = el.getBoundingClientRect(); 65 return ( 66 rect.top >= 0 && 67 rect.left >= 0 && 68 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && 69 rect.right <= (window.innerWidth || document.documentElement.clientWidth) 70 ); 71 } 72 73 // è·åæ°åçå°æ°ä½æ°ï¼å¤çå å«éå·çæ°åï¼ 74 function getDecimalCount(numStr) { 75 // ç§»é¤åä½åé符 76 var cleanNum = numStr.replace(/,/g, ''); 77 var num = parseFloat(cleanNum); 78 var str = num.toString(); 79 if (str.indexOf('.') !== -1) { 80 return str.split('.')[1].length; 81 } 82 return 0; 83 } 84 85 // è§£æå å«åä½åéç¬¦çæ°å 86 function parseFormattedNumber(numStr) { 87 // ç§»é¤åä½åé符并转æ¢ä¸ºæµ®ç¹æ° 88 return parseFloat(numStr.replace(/,/g, '')); 89 } 90 91 // æ ¼å¼åæ°åæ·»å åä½åéç¬¦ï¼æ ¹æ®éæ±å³å®æ¯å¦ä½¿ç¨ï¼ 92 function formatNumberWithCommas(num) { 93 // åªæå½æç¡®éè¦æ¶ææ·»å ååä½åé符 94 var parts = num.toString().split('.'); 95 var integerPart = parts[0]; 96 var decimalPart = parts[1] || ''; 97 98 // æ·»å åä½åé符 99 integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ','); 100 101 return decimalPart ? integerPart + '.' + decimalPart : integerPart; 102 } 103 104 // æ°åå¨ç»åå§å彿° 105 function initCountUp() { 106 $('.enfont[data-count]:not([data-count-processed])').each(function() { 107 var $this = $(this); 108 $this.attr('data-count-processed', 'true'); 109 var originalText = $this.text(); 110 $this.text('0'); 111 }); 112 } 113 114 // æ§è¡æ°åå¨ç» - ä¸èªå¨æ·»å ååä½åé符 115 function runCountUp() { 116 $('.enfont[data-count]').each(function() { 117 var $this = $(this); 118 if (isElementInViewport(this) && !$this.hasClass('counted')) { 119 var countToStr = $this.attr('data-count'); 120 var countTo = parseFormattedNumber(countToStr); 121 122 if (!isNaN(countTo)) { 123 $this.addClass('counted'); 124 125 // æ ¹æ®data-count屿§å¼çå°æ°ä½æ°æ¥å³å®decimalsåæ° 126 var decimalCount = getDecimalCount(countToStr); 127 128 // 使ç¨èªå®ä¹å¨ç»è䏿¯æä»¶ 129 var decimals = decimalCount; 130 var decimalFactor = Math.pow(10, decimals); 131 132 $({countNum: 0}).animate({countNum: countTo}, { 133 duration: 2000, 134 easing: 'swing', 135 step: function() { 136 var currentNum = Math.round(this.countNum * decimalFactor) / decimalFactor; 137 if (decimals > 0) { 138 currentNum = currentNum.toFixed(decimals); 139 } else { 140 currentNum = Math.round(currentNum); 141 } 142 // ä¸èªå¨æ·»å ååä½åé符 143 $this.text(currentNum); 144 }, 145 complete: function() { 146 var finalNum = Math.round(this.countNum * decimalFactor) / decimalFactor; 147 if (decimals > 0) { 148 finalNum = finalNum.toFixed(decimals); 149 } else { 150 finalNum = Math.round(finalNum); 151 } 152 // ä¸èªå¨æ·»å ååä½åé符ï¼ä¿æåå§æ ¼å¼ 153 $this.text(finalNum); 154 } 155 }); 156 } 157 } 158 }); 159 } 160 161 // åå§å
162 initCountUp(); 163 164 // 页é¢å è½½å®æåæ§è¡ 165 requestAnimationFrame(function() { 166 runCountUp(); 167 }); 168 169 // æ»å¨çå¬ 170 $(window).on('scroll', function() { 171 requestAnimationFrame(function() { 172 runCountUp(); 173 }); 174 }); 175 176 // çªå£å¤§å°æ¹åçå¬ 177 $(window).on('resize', function() { 178 requestAnimationFrame(function() { 179 runCountUp(); 180 }); 181 }); 182});
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.