el.scrollIntoViewIfNeeded() function is used to scroll to element el
if it's not within the visible browser area. Although it generally works well, I have encountered some issues when trying to use it with a fixed header.
I have provided an example snippet here: (Please note that this method does not work in Firefox, so the demo will not work either) https://jsfiddle.net/ahugp8bq/1/
Initially, all three colored divs are displayed below the fixed header. However, if you click on "second" and then "first", the beginning of #first
goes behind the header, which is not the desired behavior.
The issue appears to be related to the position of #otherContainer
and how its padding-top
is being ignored while scrolling up.