ddddd

scrollToTop 滚动到顶端

作者:程序员11 时间:2022-12-14 人气:351 QQ交流群\邮箱:1003265987@qq.com
scrollToTop 滚动到顶端
要展示的内容

scrollToTop(){

  clearInterval(this.timer);

  //加入定时器让他又快到慢滚动到顶部

  this.timer = setInterval(()=>{

    //获取当前scrollTop的高度位置(兼容ie和chrom浏览器)

    let oTop = document.documentElement.scrollTop || document.body.scrollTop;

    //设置速度由快到慢

    let isPeed = Math.floor(-oTop / 7);

    document.documentElement.scrollTop = document.body.scrollTop = oTop + isPeed;

    this.oScroll = true;

    if(oTop === 0){

      clearInterval(this.timer);

    }

  },30);


 /* const element = document.getElementById("body");

  element.scrollIntoView({

    behavior: 'smooth',    //平滑滚动,爽,其他还有 instant

    block: 'start'  //元素到页面顶部,其他还有 end, center

  })*/

},


温馨提示:

欢迎阅读本文章,觉得有用就多来支持一下,没有能帮到您,还有很多文章,希望有一天能帮到您。

scrollToTop 滚动到顶端---相关文章


评论区

ddddd

程序员-学习的网站-想学习编程的码农可以进来看看

首页

视频教程

购物车

我的订单