需求:锚点导航,点击导航跳到对应的模块
1.盒子滚动到指定高度 scrollTo(offsetTop每个模块顶部距离可滚动盒子的顶部偏移的像素值)
go (selector) {const height = document.querySelector(selector).offsetTopconst container = document.querySelector('.scroll-wrap')container.scrollTo({top: height,behavior: 'smooth'})},
2.元素滚动到滚动盒子的最顶部 scrollIntoView
go(selector) {document.getElementById("selector").scrollIntoView({ behavior: 'smooth' });},