DEV Community

Haruka Kakiuchi
Haruka Kakiuchi

Posted on

Smooth Scroll

Conventional way

const hoge = hoge.getBoundingClientRect();

window.scrollTo({
  left : hoge.left + window.pageXOffset, 
  top: hoge.top + window.pageYOffset,
  behavior: 'smooth',
})
Enter fullscreen mode Exit fullscreen mode

Recently way

hoge.scrollIntoView({behavior: "smooth"})
Enter fullscreen mode Exit fullscreen mode

Viewport version

document.documentElement.clientHeight
Enter fullscreen mode Exit fullscreen mode

Top comments (0)