I have the following problem:
Like Facebook, I have a menu bar at the top of the page that is always visible ( position: fixed; ). When I now click hash links on my page (or load a new page with a hash in the URL) to go to a specific element on the page, the browser always scrolls that element to the very top of the page, which means that the element is located behind the top panel menu.
I would like to add Javascript (jQuery or plain Javascript) that automatically adds a (negative) offset to this scroll position, so that the related item is located directly below the top menu bar when you click a link or the page is loaded. But I do not want to add event listeners to all the links that take care of this. I also want the solution to work if the page is loaded with a hash in the URL using the address bar of the browser (or when linking to another page with a hash at the end of the URL).
You can find the clickdummy of my page at http://loud.fm/tmp/details.html . Click on the comment bubble in the upper right corner of the image on the left to go to the comments. If your browser window is small enough, you should go to the gray “COMMENTS” headers and pagination before comments are indicated. I would like the title and pagination to appear right below the top menu after clicking the jump link.
Can you help me please? Thank you in advance!:)
Regards, Renee
javascript jquery scroll hash position
René Schubert Jul 08 2018-12-21T00: 00Z
source share