数秒後に自動スクロールするサンプル

first
(2秒後に.secondに自動スクロール)

second

<h1 class="first">first<br>(2秒後に.secondに自動スクロール)</h1>
<h1 class="second">second</h1>
const second = document.querySelector('.second')
const windowScrollTop = $(window).scrollTop()
const observer = new IntersectionObserver(function(changes)  {
  for (let i in changes) {
    if (windowScrollTop === 0 && !changes[i].isIntersecting) {
      setTimeout(() => {
        const secondTop = $('.second').offset().top
        $('html, body').animate({scrollTop: secondTop})
        observer.disconnect()
      }, 2000)
    }
  }
})
observer.observe(second)

元記事を表示する