vue实现页面滑动至指定位置

在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();
posted @ 2021-03-17 11:31  Pei你看雪  阅读(133)  评论(0)    收藏  举报  来源