I have not had any consistent success with these solutions.
Apparently due to the fact that the jump happens before Javascript => reference(http://forum.jquery.com/topic/preventing-anchor-jump)
My solution is to position all anchors at the top by default with CSS.
.scroll-target{position:fixed;top:0;left:0;}
Then use jquery to scroll to the parent of the target anchor, or a sibling(maybe an empty em tag)
<a class="scroll-target" name="section3"></a><em> </em>
jquery example for scrolling for when URL is entered with hash
(page must not be already loaded in window/tab, this covers links from other/outside sources)
setTimeout(function() {
if (window.location.hash) {
var hash = window.location.hash.substr(1);
var scrollPos = $('.scroll-target[name="'+hash+'"]').siblings('em').offset().top;
$("html, body").animate({ scrollTop: scrollPos }, 1000);
}
}, 1);
Also you'll want to prevent default for anchor clicks while on the page and then scroll to their targets
<a class="scroll-to" href="#section3">section three</a>
and jquery
$('a.scroll-to').click(function(){
var target = $(this).attr('href').substr(1);
var scrollPos = $('.scroll-target[name="'+target+'"]').siblings('em').offset().top;
$("html, body").animate({ scrollTop: scrollPos }, 1000);
return false;
});
The good thing about this method is the anchor tag targets, remain structurally beside the relevant content, although their CSS position is at the top.
This should mean that search engine crawlers won't have a problem.
Cheers, I hope this helps
Gray