【问题标题】:local scroll Anchor link offset from another Page本地滚动锚链接从另一个页面偏移
【发布时间】:2012-10-15 11:42:56
【问题描述】:

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

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

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

当您来自另一个页面时,如何给这些锚点提供偏移量?

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

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

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

【问题讨论】:

    标签: jquery scroll


    【解决方案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 某处看到的那样

    【讨论】:

      猜你喜欢
      • 2017-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-25
      • 2016-09-27
      • 1970-01-01
      • 2012-06-09
      • 1970-01-01
      相关资源
      最近更新 更多