【问题标题】:Bootstrap3, affix, fixed-top navbar, toggled text and anchorsBootstrap 3,词缀,固定顶部导航栏,切换文本和锚点
【发布时间】:2014-06-04 18:21:12
【问题描述】:

我的页面上有:

  • 固定顶部导航栏,高度为 74px;
  • 在右栏添加侧边栏导航;
  • 左栏,有可切换的内容;
<!-- initialization of affix -->
<body data-spy="scroll" data-target="#ds-right-navigation" data-offset="74">

<!-- toggleable content -->
<div class="panel">
<a id="ds-word-link-109401" data-toggle="collapse" data-target="#ds-word-109401" class="h3">1. równy</a>  
<section id="ds-word-109401" class="col-md-12 ds-word-box collapse in" style="height: auto;">
...collapseable content
</section>
</div>
<div class="panel">
... next panel
</div>

我遇到的问题如下:

  • 如果我单击带有锚点的链接,左列的内容将隐藏在固定顶部导航栏下(这个问题,我可能会使用 margin-top: -74px; padding-top: 74px 来修复)
  • 如果我折叠左侧栏中的内容,那么使用词缀的侧边栏菜单就会变得疯狂。它仍将折叠的内容视为可见,因此侧边栏突出显示错误(隐藏/折叠)的内容。

【问题讨论】:

    标签: twitter-bootstrap-3 fixed navbar sidebar affix


    【解决方案1】:
    // scroll to anchor
    if(window.location.hash) {
    var hash = window.location.hash.replace(/\/$/, "");
    if(hash.length){
      var top = $(hash).offset().top;
      //133 = 74 + 74 - 1, where 74 is offset high and -1px for affix
      $('body, html').stop().animate({ scrollTop: $(hash).offset().top -133 }, 500);
    }
    }
    
    $('a[href^=#]').on('click',function() {
    var hash = $(this).attr('href');
    if(hash !== '#') {
      // top offset is 74 and - 1px is for affix
      $('body, html').stop().animate({ scrollTop: $(hash).offset().top -73 }, 500);
    }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-13
      • 2023-03-25
      • 1970-01-01
      • 2017-07-14
      相关资源
      最近更新 更多