How to smoothly scroll an element into view using js scroll into view? or What's the best way to impl

20 Replies, 1451 Views

"Why isn't my js scroll into view working as expected?"

Hey folks!

Trying to use js scroll into view to smoothly bring an element into focus, but it’s either jumping weirdly or not working at all.

Here’s my code:
```js
document.getElementById('myElement').scrollIntoView({ behavior: 'smooth' });
```
Shouldn’t this just... work? 😅

Sometimes it scrolls, but the smooth effect is missing. Other times, nada. Am I missing something obvious?

Also, is there a better way to do this for a *seamless* UX? Maybe a polyfill or something?

Thanks in advance! 🙏

---
*PS: Using Chrome, if that helps. And yes, I checked if the element exists lol.*

Messages In This Thread
How to smoothly scroll an element into view using js scroll into view? or What's the best way to impl - by - 31-12-2024, 04:49 AM



Users browsing this thread: 1 Guest(s)