I want to do the inverse of what I\'ve been finding so far. I\'m setting a lot of heights with js and I want to navigate to the hashtag in the url after the page has loaded. I\'
Using scrollTo
or scrollIntoView
will not respect any offset created by the :target css selector, which is often used to make the page scroll to just above the anchor, by setting it to position: relative
with a negative top
.
This will scroll to the anchor while respecting the :target
selector:
if (location.hash) {
window.location.replace(location.hash);
}