$(document).ready(function () { $(window).scroll(function () { //首页数字跳动 var bolexec = false; if ($(".line").length > 0) { if($(window).scrolltop() > ($("#indexsuzi").offset().top-300)){ var winheight = $(window).height() / 1.1; var current = $(".line").offset().top; if ($(document).scrolltop() > current / 1.3 && bolexec == false) { var line = $(".line"), len = line.length; line.each(function (index, element) { var t = $.trim($(this).text()).replace(" ", "").length; var text = ""; for (var j = 0; j < t; j++) text += 0; $(this).text(text); }); function animate(i) { if (i < len) { var _this = line.eq(i), a = 0, v = _this.attr("data-leg") - 0, _time = 150, vlen = (v + "").length; var t = setinterval(function () { a += 1; var pi = parseint(v / 150 * a); var text = ""; for (var j = 0; j < vlen - (pi + "").length; j++) text += 0; _this.text(text + pi); if (a == _time / 2) animate(i + 1); if (a >= _time) clearinterval(t); }, 1); } } animate(0); bolexec = true; } } // } }) })