Requirements: Anchor point navigation problem, click on the navigation to jump to the corresponding module, two ways
1. The scroll box scrolls to the specified height scrollTo (offsetTop pixel value offset from the top of each module to the top of the scrollable box)
goAnthor (selector) {
const height = document.querySelector(selector).offsetTop
const container = document.querySelector('.scroll-wrap')
container.scrollTo({
top: height,
behavior: 'smooth'
})
},
2. The scroll element scrolls to the top of the scroll box scrollIntoView
goAnthor(selector) {
document.querySelector(selector).scrollIntoView({
behavior: 'smooth'
})
},