backTop() {
const timer = setInterval(() => {
const top = document.documentElement.scrollTop
const speed = Math.ceil(top / 2)
document.documentElement.scrollTop = top - speed
if (top === 0) {
clearInterval(timer)
}
}, 20)
}
使用定时器每次高度都取一半并向上取整,这样就可以平滑的滚动顶部去