Min's blog

I choose to see the beauties in the world.

导航

vue回到顶部

Posted on 2019-10-12 10:21  Min77  阅读(142)  评论(0编辑  收藏  举报
  backTop() {
      var top = document.body.scrollTop || document.documentElement.scrollTop;
      this.duration -= 3;
      this.duration = this.duration <= 0 ? 1 : this.duration;
      var speed = top / this.duration;
      document.documentElement.scrollTop -= speed;
      if (top > 0) {
        this.timer = setTimeout(() => {
          this.backTop();
        }, 16);
      } else {
        this.duration = 50;
        clearTimeout(this.timer);
        
      }
    }