我有一个网站,导航栏固定在顶部,主要内容区域下面有3个div.
我正在尝试从bootstrap框架中使用scrollspy.
当你滚动浏览div时,我已成功突出显示菜单中的不同标题.
我也有它,所以当你点击菜单时,它会滚动到页面的正确部分.但是,偏移是不正确的(它不考虑导航栏,所以我需要偏移约40像素)
我在Bootstrap页面上看到它提到了一个偏移选项,但我不确定如何使用它.
当它说你可以使用scrollspy时$('#navbar').scrollspy(),我也不是它的意思,我不知道在哪里包含它所以我没有,一切似乎都在工作(除了偏移).
我认为偏移可能是data-offset='10'身体标签,但它对我没有任何作用.
我觉得这是非常明显的事情,我只是错过了它.有帮助吗?
我的代码是
...
<!-- note: the data-offset doesn't do anything for me -->
<body data-spy="scroll" data-offset="20">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">VIPS</a>
<ul class="nav">
<li class="active">
<a href="#trafficContainer">Traffic</a>
</li>
<li class="">
<a href="#responseContainer">Response Times</a>
</li>
<li class="">
<a href="#cpuContainer">CPU</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="span12">
<div id="trafficContainer" class="graph" style="position: relative;">
<!-- graph goes here -->
</div> …Run Code Online (Sandbox Code Playgroud) 我正在使用Twitter Bootstrap构建一个站点,并在页面顶部有一个40px固定位置导航栏.我设置了一些锚点以跳转到整个页面中的各种H1,但锚点目标最终被导航栏部分遮挡.有没有办法将链接偏移到导航栏的帐户?我已经看到一个建议将每个锚放在它自己的偏移div中,但这似乎是很多重复的代码,我想知道是否还有另一种方法.
如果可能的话,我宁愿用CSS而不是jQuery来做这件事,但任何解决方案都是受欢迎的.
.topbar {
height: 40px;
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 10000;
overflow: visible;
}
body {
padding-top: 40px;
/* 40px to make the container go all the way to the bottom of the topbar */
font-family: 'Proxima', "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 18px;
font-weight: normal;
color: #555;
background-color: #eee;
}
Run Code Online (Sandbox Code Playgroud)
谢谢!