"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.*
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.*
