html:
<div >
<div >350</div>
<div >323435</div>
<div >7</div>
<div >25</div>
</div>
css:
.flexW{display:flex;justify-content: space-between;}
.num{width:23%;}
js:
$.fn.numChange = function(){
var _this = this;
$(window).scroll(function(){
if($(window).scrollTop()>(_this.offset().top-$(window).height()-100)){
if(!_this.attr('data-change')){
_this.find('.num').each(function(){
let endNum = $(this).text()*100,
startNum = 0,
time = 100,
speed = 30,
addNum = Math.round(endNum/time),
_this = $(this);
_this.text(0);
var numChange = setInterval(function(){
startNum += addNum;
_this.text(Math.round(startNum/100));
if(startNum >= endNum){
clearInterval(numChange);
}
},speed)
});
}
_this.attr('data-change','true');
}
});
}
$('.flexW').numChange();
$(window).trigger('scroll');
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/916.html
標籤:jQuery
上一篇:簡單的事件和DOM操作
下一篇:無聊試著寫個商品放大鏡功能
