1

I have a sidebar menu that links to anchors on the page and on other pages. When I'm in the page the anchors work just fine, however when I go to an anchor on another page it offsets the height of the sticky header by more than it should. How can I get it to go to offset the header properly?

This is the code I'm using:

jQuery(function($) { 


$('a[href^="#"]').live('click',function(event){
    event.preventDefault();
    var target_offset = $(this.hash).offset() ? $(this.hash).offset().top : 0;
    //change this number to create the additional off set        
    var customoffset = 85;
    $('html, body').animate({scrollTop:target_offset - customoffset}, 500);
});

}(jQuery));
FilT
  • 192
  • 4
  • 13
  • This code handles link clicks on the current site only. If you navigate to another page, then you have to call any code that is supposed to scroll somewhere in that other page. (Means, checking if a hash is set and there is a corresponding element when the page loads.) – CBroe Feb 10 '17 at 11:55
  • I've been searching for a solution and I cannot find the way that you're telling me. Can you give me some light with the coding? I'm kinda new to JQuery – FilT Feb 10 '17 at 17:12
  • 1
    You can try to [find](http://stackoverflow.com/questions/9652944/jquery-scroll-to-id-from-different-page) in here a better solution, although i think you need to change somethings, let me know if you need any help.@CBroe i think that is not a good answer for a person who tries to find a solution here. If you don't like the question/help please don't answer to anyone. Stackoverflow is more than this kind of answer like yours. – AcceptableDuck Feb 10 '17 at 18:57

0 Answers0