Bootstrap的Scrollspy:在页面重新加载后滚动具有不同偏移量时的偏移量

时间:2015-09-26 16:16:33

标签: jquery twitter-bootstrap scrollspy

我的SPA网站(单页应用程序)上的导航卷轴出现问题。当我正常滚动我的网站时,偏移是正确的,导航得到正确的活动类。现在,当我停留在页面上的某个位置作为" about"时,我的导航具有正确的活动类。但是当我刷新网站并且我的浏览器滚动回到同一点时,我的导航会得到"联系"活跃的课程实际上只是在#34;关于"。在我再次向下滚动之后,我得到了关于"关于"再次活跃。

我尝试了几件事,但没有任何效果。

更新 我通过给出所有部分最小屏幕高度来解决问题:



html {
  height:100% !important;
}

body {
  height:100%;
}

section {
  min-height:100%;
}




1 个答案:

答案 0 :(得分:0)

请提供:“如何创建最小,完整且可验证的示例”

  

https://stackoverflow.com/help/mcve

根据你提到的内容:

  

http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_js_scrollspy_refresh&stacked=h

$(document).ready(function(){
removeSection = function(e){
    $(e).parents("body > div").remove();
    $('body').each(function(){
//Try this refresh method if you haven't already.
        $(this).scrollspy('refresh');
    });
}
$("body").scrollspy({target: ".navbar", offset: 50});

});