在Vue中,有三种方式可以实现页面滑动至指定位置
方法1:
//先获取目标位置距离
mounted() {
this.$nextTick(() => {
setTimeout(() => {
let targetbox= document.getElementById('targetbox');
this.target= targetbox.offsetTop;
})
})
}
//再滑动指定距离
document.body.scrollTop = this.target;
方法2:
this.$nextTick(() => {
this.$refs.DOM.scrollTo(0,200);
this.$refs.result.scrollIntoView({ behavior: "smooth" });
})
方法3:
document.getElementById("target").scrollIntoView();
版权声明:本文为qq_42992729原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。