What's the best way to implement js scroll to element smoothly? or How can I use js scroll to element

14 Replies, 650 Views

For a super simple js scroll to element, this works pretty well:

```js
document.querySelector('#yourElement').scrollIntoView({
behavior: 'smooth',
block: 'start'
});
```

But if you want fancy easing, you’ll need to roll your own or use a lib. Check out https://greensock.com/scrolltoplugin/ for GSAP’s solution—it’s worth the small footprint.

Messages In This Thread



Users browsing this thread: 1 Guest(s)