vue项目中平缓滑到到指定区域
先diss一下 网上很多帖子 各种不靠谱 一个平缓滑动看了二十多篇文章 结果一行代码搞定 彻底崩溃
话不多说 直接上代码
<button class="navBtn" @click="tiaozhuan('banner')">首页</button>
在指定位置为元素添加id名称
<div id="banner">
方法:
tiaozhuan(sectionId) {//sectioned为id名称
document.getElementById(sectionId).scrollIntoView({ block: 'start', behavior: 'smooth' })
},