PageSourceSearch

https://www.digitalchina.com/statics/zhsite/js/number.js

js digitalchina.com collected 2026-10-02 03:08:08 UTC 2,049 bytes, 75 lines download raw bytes

1$.fn.countTo = function(options) {
2	options = options || {};
3	return $(this).each(function() {
4		var settings = $.extend({},
5		$.fn.countTo.defaults, {
6			from: $(this).data('from'),
7			to: $(this).data('to'),
8			speed: $(this).data('speed'),
9			refreshInterval: $(this).data('refresh-interval'),
10			decimals: $(this).data('decimals')
11		},
12		options);
13		var loops = Math.ceil(settings.speed / settings.refreshInterval),
14		increment = (settings.to - settings.from) / loops;
15		var self = this,
16		$self = $(this),
17		loopCount = 0,
18		value = settings.from,
19		data = $self.data('countTo') || {};
20		$self.data('countTo', data);
21		if (data.interval) {
22			clearInterval(data.interval);
23		}
24		data.interval = setInterval(updateTimer, settings.refreshInterval);
25		render(value);
26		function updateTimer() {
27			value += increment;
28			loopCount++;
29			render(value);
30			if (typeof(settings.onUpdate) == 'function') {
31				settings.onUpdate.call(self, value);
32			}
33			if (loopCount >= loops) {
34				$self.removeData('countTo');
35				clearInterval(data.interval);
36				value = settings.to;
37				if (typeof(settings.onComplete) == 'function') {
38					settings.onComplete.call(self, value);
39				}
40			}
41		}
42		function render(value) {
43			var formattedValue = settings.formatter.call(self, value, settings);
44			//console.log(self, value, settings)
45			$self.html(formattedValue);
46		}
47	});
48};
49$.fn.countTo.defaults = {
50	from: 0,
51	to: 0,
52	speed: 1000,
53	refreshInterval: 100,
54	decimals: 0,
55	formatter: formatter,
56	onUpdate: null,
57	onComplete: null
58};
59function formatter(value, settings) {
60	return value.toFixed(settings.decimals);
61}
62$('.count-number').each(function() {  
63	var $this = $(this);  
64	count.call($this);  // 使用.call()确保this指向当前元素  
65});
66
67function count() {  
68    var $this = $(this);  
69    var options = $.extend({},  
70        $.fn.countTo.defaults,  
71        $this.data(),  // 使用$this.data()来获取所有data-*属性  
72        $this.data('countToOptions') || {}  // 覆盖默认选项和data-*属性  
73    );  
74    $this.countTo(options);  
75}

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.