scroll page down after anchor?

asked Mar 11, 2013 in General by deepa1 (1,580 points)
I have recently added a fixed menu at the top of my page. But I have an issue when any anchor link is clicked the page scrolls to the anchor which is now covered with the newly placed top menu. How can I catch the anchor event using javascript?

2 Answers

0 like 0 dislike
answered Mar 11, 2013 by TopNet (10,360 points)
0 like 0 dislike
answered Mar 12, 2013 by WebGuru (9,280 points)
You have to calculate the offset of the element so you can scroll to the element’s offset  position:
    // height of the navigation bar
    var height= $("#nav").outerHeight();
    // referenced dom-element position
    var pos = $($(this).attr("href")).position().top;
    // scroll to your element
    // override default
    return false;