Vue scrolls smoothly to the specified position

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'
      })
    },

Guess you like

Origin blog.csdn.net/qq_33168578/article/details/123373246