function numberanimation(){ var idx; var supply = document.queryselectorall(".numberlist"); var supplys=[]; if(supply.length>0){ supplys = $(".numberlist")[0].classlist; idx= $.inarray("active", supplys); } if(idx<0){ var numlist = document.queryselectorall(".number"); numlist.foreach(e=>{ var time = e.getattribute('data-time'); var sum = e.getattribute('data-num'); var speed = math.ceil(time / 20); var increment = math.round(sum / speed); var number = 1; e.timer = setinterval(function () { if(number < sum){ number += increment; e.innertext = number; }else{ e.innertext = sum; clearinterval(e.timer); } },100); }) $(".numberlist").removeclass("active").addclass("active"); } } function item(){ $(".animate-box").removeclass("animate"); var height = document.body.clientheight; var items = document.queryselectorall(".item"); var itemone = items[0]; var itemtop = itemone.offsettop; if(itemtop <= height){ settimeout(function() { $('.contains').addclass("animate"); }, 100); } var scroll = function(conf) { this._node = ".item"; this._heights = []; this.callback = conf.callback || function(index) { console.log(index) }; this._len = $(this._node).length; this.init(); }; scroll.prototype = { getheight: function() { var self = this; $(self._node).each(function(k, v) { self._heights[k] = v.offsettop; }); self._heights[self._len] = 1000000000000000; }, checkpos: function(sctop) { var self = this; for(var i in self._heights) { if((sctop + $(window).height() / 2) >= self._heights[i]) { self.callback(i); } } }, init: function() { var self = this; self.getheight(); $(window).on("scroll", function() { self.getheight(); self.checkpos($(window).scrolltop()); }); } }; var scroll1 = new scroll({ callback: function(index) { index = parseint(index); $(".animate-section").eq(index).find(".animate-box").addclass("animate"); $(".animate-section").eq(index).find(".animate-box1").addclass("animate"); numberanimation(); } }); } $(document).ready(function(){ //往上滑动画效果 window.onload = function(){ item(); } window.onresize = function(){ item(); } })