废话不多说先上代码
<div class="back-top-item" @click="turnFeeConsultation">
<div class="feeConsultation"></div>
<p class="text">收费咨询</p>
</div>
turnFeeConsultation() {
this.$nextTick(() =>
document.getElementsByClassName('paidConsultation')[0].scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' });
});
}
scrolIintoView 布尔值参数
- scrollintoView(true) 或者scrollIntoView()相当于scrollIntoViewOptions: {block: “start”, inline: “nearest”}
- scrollintoView(false) 相当于scrollIntoViewOptions: {block: “end”, inline: “nearest”}
scrolIintoView 布对象参数
- behavior(可选)定义动画过渡效果, “auto” 瞬间跳转(没有动画效果)或 “smooth”(由动画效果平滑的到指定位置) 之一。默认为 “auto”
- block(可选)定义垂直方向的对齐, “start”, “center”, “end”, 或 "nearest"之一。默认为 “start”。
- inline(可选)定义水平方向的对齐, “start”, “center”, “end”, 或 "nearest"之一。默认为 “nearest”