I have a div which contains a table for tabs in my site navigation. I have the div set to overflow when in mobile like this:
I want to have the div scroll to the, currently hidden, active tab automatically like this:
In another SA question it was suggested to use scrollIntoView
. Tested it in the console and it works fine:
document.getElementById("active_tab").scrollIntoView({block: "end"})
I even used the jQuery version scrollintoview
:
$('#active_tab').scrollintoview();
and it works fine. The trouble is that when I add the actual code (either one) to my site the overflow div on scrolls some random amount (seems to be half way). Here is an example:
Tried this in Chrome and Safari. Am I missing something obvious? I am not trying to scroll the whole page - just that div that has hidden overflow. Very odd that it work direct in the console but not in my code direct and for both JS and JQ. As far as I know there is no other JS etc related to this div etc.