I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
One problem with scrollIntoView is that it scrolls the window until the top of the element is inside the viewport, but many sites (like DEV, for example) have a fixed header.
If you try it on an element on this page, then the element will remain partially hidden under the header. You'll end up needing to follow the scrollIntoView call with one to window.scrollBy passing in the height of the header as currently rendered (so reading it from the element rather than CSS)
One problem with
scrollIntoView
is that it scrolls the window until the top of the element is inside the viewport, but many sites (like DEV, for example) have a fixed header.If you try it on an element on this page, then the element will remain partially hidden under the header. You'll end up needing to follow the
scrollIntoView
call with one towindow.scrollBy
passing in the height of the header as currently rendered (so reading it from the element rather than CSS)I don't really call that a problem as you're wanting to do something this function doesn't provide.
But yes it's definitely a gotcha at first if your using fixed/sticky elements 👍