0

我目前正在使用 css-tricks 中的代码在此处对我的锚点执行自动滚动功能:

http://css-tricks.com/snippets/jquery/smooth-scrolling/

我需要做什么来抵消“页面顶部”?基本上我想让页面从锚点位置停止大约 150 像素..

谢谢!!!!

4

2 回答 2

1

换行:

var targetOffset = $target.offset().top;

到:

var targetOffset = $target.offset().top - 150;

这会将其推高 150 像素,比您定位的顶部高出 150 像素。

关于哈希:

改变这个:location.hash = target;

到:

if(history.pushState) {
    history.pushState(null, null, target);
}
else {
    location.hash = target;
}
于 2012-06-13T03:21:01.570 回答
1

搞砸的部分在这里:

location.hash = target;

删除它,并改用

history.pushState({}, "", "#"+target);

如果pushState不支持,那么您可以使用History.js

于 2012-06-13T03:35:52.257 回答