js实现页面自动滚动方法

记录一下页面自动滚动方法

首先实现自动滚动方法

  // 滚动代码
  const scrollToTop = () =>{
    var hScrollTop = document.getElementById('app').scrollTop;
    var hScrollHeight = document.getElementById('app').scrollHeight;
    var height = 1
    console.log(hScrollTop+" "+hScrollHeight+" "+height);
    if((height+hScrollTop)>=hScrollHeight){//滚动条已经到了容器底部
      document.getElementById('app').scrollTop=0;
    }else{
      var h = hScrollTop + height;
      document.getElementById('app').scrollTop=h;
      window.requestAnimationFrame(scrollToTop)
    }
  }

之后调节每次滚动高度

 var height = 1

最后在执行方法

    scrollToTop()

这样就页面自动滚动了 -----记录一下


版权声明:本文为FZbucuo原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。