3

我有一个带有常见问题解答部分的页面,其中带有锚标记,单击时将动画到特定条目。

Aditionaly 我有一个固定的 Navi,所以我确实在 jquery 中设置了一个锚点偏移量。

现在我在起始页上有一个指向特定常见问题解答条目的锚链接。该链接会将您正确地引导到条目,但当然不会附加偏移量,因为不会以这种方式触发本地滚动。

当你来自另一个页面时,怎么可能给这些锚点一个偏移量?

我试图将:附加.wrapperdiv{ position:relative; top:-10px; } 到每篇文章。但这无济于事。

你可以在这里看到整个事情:

页面indexpage 上的anchorlinks 链接是三个图标上的链接。

4

1 回答 1

1

您可以测试以下内容:

<script type="text/javascript">

// Check if there's an anchor in the url
if (window.location.hash){
    var id = window.location.hash.substring(1);
}

// then on window load scroll to the called anchor (that will trigger the window scroll 
// so your upper menu can appear again)
$(window).load(function() {
  if (window.location.hash){
    $.scrollTo('#'+id, 300 // uncomment to set offset if you like, {offset: -70}
  );
 }
});

</script>

我假设您在 js 文件中定义了函数 $.scrollTo(),正如我在http://rueegg-praxis.ch/minimeecache/1349103535a17a59c76f4994e40f602abc25dd4d8b.js的某处看到的那样

于 2012-12-20T19:43:38.937 回答