vue 平滑回到顶部
methods: { // 回到顶部 goTop() { cancelAnimationFrame(this.timer) const self = this self.timer = requestAnimationFrame(function fn () { const oTop = document.body.scrollTop || document.documentElement.scrollTop if (oTop > 0) { document.body.scrollTop = document.documentElement.scrollTop = oTop - 50 self.timer = requestAnimationFrame(fn) } else { cancelAnimationFrame(self.timer) } }) } }

浙公网安备 33010602011771号