版权声明:本文为CSDN博主「hh22。」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_44953689/article/details/108364985
// 点击此处
<div @click="goDingyue">立即订阅</div>
// 跳转到该位置
<div class="dingyue_box" ref="dingyue_box">
立即订阅内容
</div>
methods: {
goDingyue() {
// 获取元素在页面中的位置
console.log(this.$refs.dingyue_box_ref.getBoundingClientRect());
// 跳转到指定位置并且平滑滚动
this.$el
.querySelector(".dingyue_box")
.scrollIntoView({ block: "start", behavior: "smooth" });
},
}