Vue点击滑动到指定的位置
<!-- 跳转的指定元素 -->
<div class="tab_content3" ref="design_up"></div>
// 滚动到指定位置
toDesign_up() {
// 需要跳转的元素 <div ref="design_up"></div>
let total = this.$refs["design_up"].offsetTop;
console.log(document.documentElement.scrollTop || document.body.scrollTop)
let distance =
document.documentElement.scrollTop || document.body.scrollTop;
// 平滑滚动,时长500ms,每10ms一跳,共50跳
let step = total / 50;
var timer = setInterval(() => {
if (distance < total) {
distance += step;
document.body.scrollTop = distance;
document.documentElement.scrollTop = distance;
} else {
clearInterval(timer);
}
}, 10);
// document.documentElement.scrollTop = top;
},