将页面滚动到指定区域
通过scrollIntoView()来实现,将页面滚动到指定元素区域
<div id="box"></div>
let boxDom = document.querySelector('#box');
boxDom.scrollIntoView({ behavior: "smooth" });
点击回到顶部
<div @click="scrollToTop"></div>
scrollToTop() {
// let top = document.documentElement.scrollTop || document.body.scrollTop ; 距离顶部距离
window.scrollTo({
top: 0,
behavior: "smooth",
});
},