vue 点击回到顶部

 代码:

顶部
showbtn() {
      const scrollTop =
          window.pageYOffset ||
          document.documentElement.scrollTop ||
          document.body.scrollTop
      this.scrollTop = scrollTop
      if (scrollTop > 200) {
        this.showBtn = true
      } else {
        this.showBtn = false
      }
 },
backTop() {
      const timer = setInterval(function() {
        const osTop =
          document.documentElement.scrollTop || document.body.scrollTop
        const ispeed = Math.floor(-osTop / 5)
        document.documentElement.scrollTop = document.body.scrollTop =
            osTop + ispeed
        this.isTop = true
        if (osTop === 0) {
          clearInterval(timer)
        }
      }, 3)
  },

图案实例展示:

vue 点击回到顶部_第1张图片

你可能感兴趣的:(vue,vue.js,javascript,前端)