element.prototype.elementinview = function() { var rect = this.getboundingclientrect() var yinview = rect.top < window.innerheight && rect.bottom > 0 var xinview = rect.left < window.innerwidth && rect.right > 0 return yinview && xinview } var wormdigitalscroll = function(options) { var that = this, dqtime for (var i in options) this[i] = options[i] if (!this.el) { return false } // var strnum = parseint(this.el.innerhtml) var strnum = this.el.innerhtml var mc = strnum / this.time var start = false; function update(str) { that.el.innerhtml = str } function startnum() { if (that.el.elementinview() && !start) { start = true var starttimeout = new date().gettime() var time = setinterval(function() { dqtime = new date().gettime() - starttimeout if (dqtime >= that.time) { clearinterval(time) update(strnum) window.removeeventlistener('scroll', scroll, false) } else { var decimal = string(strnum).split('.') if (decimal.length > 1) { decimal = string(strnum).split('.')[1].length } else { decimal = 0 } update((mc * dqtime).tofixed(decimal)) } }, 0) } } function scroll() { startnum() } startnum() window.addeventlistener('scroll', scroll, false) } wormdigitalscroll.prototype = { el: null, time: 500 } $(function () { numbox() }) function numbox(){ if($('.wel_02 ').length>0){ for (var i = 0; i < $('.wel_02 span').length; i++) { new wormdigitalscroll({ el: $('.wel_02 span').eq(i).find('em').length > 0 ? $('.wel_02 span').eq(i).find('em').get(0) : $('.wel_02 span').eq(i).get(0), time: 3000 }) } } }