利用锚点改变事件(onhashchange),使用jQuery的(scrollTop)向前滚回导航栏的高度(比如我的100个像素)
HTML:
<body onhashchange="fix_the_nav();">
</body>
js:
function fix_the_nav() {
if(window.location.hash){
var target = $(location.hash);
$("body,html").scrollTop(target.offset().top-100); // my nav size is 100px
}
}
Done.