PageSourceSearch

https://feiya.com/js/index.js

js feiya.com collected 2026-10-06 19:20:43 UTC 3,331 bytes, 103 lines download raw bytes

1
2
3
4var wrapTop = $(".digital").offset().top;
5var istrue = true;
6$(window).on("scroll",
7    function() {
8        var s = $(window).scrollTop();
9        if (s > wrapTop - 900 && istrue) {
10            $(".timer").each(count);
11
12            function count(a) {
13                var b = $(this);
14                a = $.extend({},
15                    a || {},
16                    b.data("countToOptions") || {});
17                b.countTo(a)
18            };
19            istrue = false;
20        };
21    })
22//设置计数
23$.fn.countTo = function(options) {
24    options = options || {};
25    return $(this).each(function() {
26        //当前元素的选项
27        var settings = $.extend({}, $.fn.countTo.defaults, {
28            from: $(this).data('from'),
29            to: $(this).data('to'),
30            speed: $(this).data('speed'),
31            refreshInterval: $(this).data('refresh-interval'),
32            decimals: $(this).data('decimals')
33        }, options);
34        //更新值
35        var loops = Math.ceil(settings.speed / settings.refreshInterval),
36            increment = (settings.to - settings.from) / loops;
37        //更改应用和变量
38        var self = this,
39            $self = $(this),
40            loopCount = 0,
41            value = settings.from,
42            data = $self.data('countTo') || {};
43        $self.data('countTo', data);
44        //如果有间断,找到并清除
45        if (data.interval) {
46            clearInterval(data.interval);
47        };
48        data.interval = setInterval(updateTimer, settings.refreshInterval);
49        //初始化起始值
50        render(value);
51
52        function updateTimer() {
53            value += increment;
54            loopCount++;
55            render(value);
56            if (typeof(settings.onUpdate) == 'function') {
57                settings.onUpdate.call(self, value);
58            }
59            if (loopCount >= loops) {
60                //移出间隔
61                $self.removeData('countTo');
62                clearInterval(data.interval);
63                value = settings.to;
64                if (typeof(settings.onComplete) == 'function') {
65                    settings.onComplete.call(self, value);
66                }
67            }
68        }
69
70        function render(value) {
71            var formattedValue = settings.formatter.call(self, value, settings);
72            $self.html(formattedValue);
73        }
74    });
75};
76$.fn.countTo.defaults = {
77    from: 0, //数字开始的值
78    to: 0, //数字结束的值
79    speed: 1000, //设置步长的时间
80    refreshInterval: 100, //隔间值
81    decimals: 0, //显示小位数
82    formatter: formatter, //渲染之前格式化
83    onUpdate: null, //每次更新前的回调方法
84    onComplete: null //完成更新的回调方法
85};
86
87function formatter(value, settings) {
88    return value.toFixed(settings.decimals);
89}
90//自定义格式
91$('#count-number').data('countToOptions', {
92    formmatter: function(value, options) {
93        return value.toFixed(options.decimals).replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
94    }
95});
96//定时器
97$('.timer').each(count);
98
99function count(options) {
100    var $this = $(this);
101    options = $.extend({}, options || {}, $this.data('countToOptions') || {});
102    $this.countTo(options);
103};

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.