TIPS:页面(容器)可滚动时才能用!
实例:
页面
<div>
<span id='baseVideo1'></span>
<span id='baseVideo2'></span>
<span id='baseVideo3'></span>
<button @click='gotoSite'></button>
</div>
js
gotoSite () {
this.$el.querySelector('#baseVideo2').scrollIntoView({
behavior: 'auto', // 平滑过渡
block: 'center'
});
}
参数
behavior(可选):定义动画过渡效果,instant表示直接滚动,smooth表示平滑滚动
block(可选):定义垂直方向对齐。start表示将视口的顶部和元素顶部对齐;center表示将视口的中将和元素的中间对齐,end表示将视口的底部和元素的底部对齐,nearest表示就近对齐
inline(可选):定义水平方向的对齐。可选值start,center,end,nearest,意思和block属性赋值一样