实现方式:
element.scrollIntoView({
behavior: 'smooth', //平滑滚动,爽,其他还有 instant
block: 'start' //元素到页面顶部,其他还有 end, center
})
案例:
var backtotop = document.querySelector("body");
backtotop.scrollIntoView({
behavior: 'smooth',
block: 'start'
})