File: /www/wwwroot/www.scdc-marine.com/wp-content/themes/scdc-marine/assets/js/jquery.hekunum.js
// 使用指南 data-num 动态目标数字 默认3000
// 默认格式 <span class="HekuNum" data-num="120" data-time="4000" > </span>
// data-time 动态总共用时 默认:3000ms 默认30ms 跳动一次 所以默认最低 数字 100 若目标数字小于100 需要手动配置此参数 为 目标参数 data-num X 30
// 动画只执行一次,执行一次后 注入data("start", !0) 标记
(function($) {
$.fn.num_running = function() {
function n() {
var t = $(".HekuNum");
var n = {
top: $(window).scrollTop(),
bottom: $(window).scrollTop() + $(window).height()
};
t.each(function() {
var num = $(this).data("num") > 0 ? $(this).data("num") : 3000;
var time = parseInt($(this).data("time")) > 0 ? parseInt($(this).data("time")) : 3000;
n.top <= $(this).offset().top + $(this).height() && n.bottom >= $(this).offset().top && !$(this).data("start") &&
($(this).data("start", !0), new AnimateNum({
obj: $(this),
target: num,
totalTime: time
}))
})
}
$(document).ready(function(){
n();
});
$(window).bind("scroll", function() {
n();
});
function AnimateNum(t) {
this.obj = t.obj, this.target = t.target.toString(), this.totalTime = t.totalTime || 1000, this.init()
}
AnimateNum.prototype = {
init: function() {
return this.target ? (this.animation(), void 0) : !1
},
animation: function() {
var t = this,
i = this.target.indexOf("."),
e = 0;
i >= 0 && (e = this.target.length - i - 1);
var n = this.target.replace(".", ""),
s = this.totalTime / 30 | 0,
s1 = s-14,
a = n / s | 0,
r = 0,
h = 0,r1 = 0,r2 = 0,r3 = 0;
t.timer30 = setInterval(function() {
r++, h += a, t.obj.html(h / Math.pow(10, e)), r >= s1 && (clearInterval(t.timer30),(t.timer90 = setInterval(function() {
r1++, h += a, t.obj.html(h / Math.pow(10, e)), r1 >= 7 && (clearInterval(t.timer90),(t.timer180 = setInterval(function() {
r2++, h += a, t.obj.html(h / Math.pow(10, e)), r2 >= 5 && (clearInterval(t.timer180),(t.timer400 = setInterval(function() {
r3++, h += a, t.obj.html(h / Math.pow(10, e)), r3 >= 2 && (clearInterval(t.timer400), t.obj.html(t.target))
}, 400)))
}, 180)))
}, 90)))
}, 30);
}
};
}
})(jQuery);