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

14 Replies, 681 Views

Hey! For a smooth js scroll to element, I’ve had good luck with `element.scrollIntoView({ behavior: 'smooth' })`. It’s vanilla JS and works decently across browsers.

If you want custom easing, you might need to ditch the native smooth scroll and use `requestAnimationFrame` with a custom easing function. Check out this tutorial on CSS-Tricks for a deep dive: https://css-tricks.com/snippets/jquery/s...scrolling/ (yes, it’s jQuery, but the logic translates to vanilla).

Also, Safari can be a pain—polyfills like `smoothscroll-polyfill` might help if you’re hitting inconsistencies.

Messages In This Thread



Users browsing this thread: 1 Guest(s)