我的 SPA 网站(单页应用程序)上的导航滚动间谍有问题。当我在网站上正常滚动时,偏移量是正确的,并且导航获得正确的活动类。现在,当我停留在页面上的某个位置(例如“关于”)时,我的导航具有正确的活动类。但是,当我刷新网站并且浏览器将我滚动回到同一点时,我的导航会“接触”活动类,而活动类实际上就在“关于”下方。当我向下和向上滚动一次后,我再次激活“关于”。
我尝试了一些方法,但没有任何效果。
更新: 我通过给出所有部分的最小屏幕高度解决了这个问题:
html {
height:100% !important;
}
body {
height:100%;
}
section {
min-height:100%;
}
根据你提到的内容:
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});
});