单页面:有多个setTimeout,每个setTimeout频率在50到100毫秒之间,谷歌浏览器CPU已经爆到40~50%,请教高手改如何优化。
// 纵向鼠标进入 - 继续滚动
hgo(){
window.onmousewheel = document.onmousewheel = null;
var _this = this;
if(this.htimer){
clearTimeout(this.htimer);
this.htimer = null;
}
this.htimer = setTimeout(function(){
if(_this.hscrollH > _this.hscrollMove){
_this.hscrollH -= _this.hscrollYBW;
_this.scrollBarM += _this.scrollBarBF;
}else{
_this.hscrollH = 0;
_this.scrollBarM = 0;
}
clearTimeout(this.htimer);
_this.hgo();
},100)
},
_go(s){//s为列表没行数据的单独的计时器对象
var _this = this;
if(s.timer){
clearTimeout(s.timer);
s.timer = null;
}
s.timer = setTimeout(function(){
if(s.scrollH > s.scrollMove){
s.scrollH -= 3;
}else{
s.scrollH = 0;
}
_this._go(s);
},150)
},