setTimeout频率50毫秒导致CPU吃紧

单页面:有多个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)
      },
阅读 1.8k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题