gpt4 book ai didi

twitter-bootstrap - bootstrap scrollspy sidenav 不工作 - 最后一项选择

转载 作者:行者123 更新时间:2023-12-03 00:06:52 28 4
gpt4 key购买 nike

我正在尝试制作一个粘性的 self 突出侧边栏来工作,并且花了很长时间才弄清楚我错过了什么。内容包括 data-spy="scroll"data-target=".sidenav"属性,但只有 sidenav 中的最后一个项目突出显示,并且滚动时没有任何 sidenav 项目突出显示。我有一个 jsfiddle 示例:

http://jsfiddle.net/b8JkE/

(调整结果 Pane 的宽度,使 .sidenav float 到左侧)

遵循文档 http://twitter.github.com/bootstrap/javascript.html#scrollspy

$('.sidenav') 已被 affix() 编辑。 div.sidenav 有一个 ul w/class="nav nav-tabs nav-stacked"。有一个内容 div w/data-spy="scroll"data-target=".sidenav",但是在页面加载时,导航中的最后一项会突出显示,并且滚动时没有任何更新。我错过了什么?

html:

  <div class="container">
<div class="row">
<div class="span2 sidenav-parent">
<div class="sidenav">
<ul class="nav nav-tabs nav-stacked">
<li><a href="#a">a</a></li>
<li><a href="#b">b</a></li>
<li><a href="#c">c</a></li>
<li><a href="#d">d</a></li>
<li><a href="#e">e</a></li>
</ul>
</div>
</div>
<div class="span10" id="gimmelove" data-spy="scroll" data-target=".sidenav">
<h4 id="a">a</h4><p>Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party lo cavore wolf cliche high life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.</p>
<h4 id="b">b</h4><p>Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party lo cavore wolf cliche high life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.</p>
<h4 id="c">c</h4><p>Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party lo cavore wolf cliche high life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.</p>
<h4 id="d">d</h4><p>Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party lo cavore wolf cliche high life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.</p>
<h4 id="e">e</h4><p>Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party lo cavore wolf cliche high life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.</p>
</div>
</div>
</div>​

CSS:

body { margin-top: 20px; }
#gimmelove { background-color:#f3f3f3; }
.sidenav .active a { font-weight:600; background-color:#f3f3f3; }

​js:

$('.sidenav').affix();

最佳答案

我自己也遇到过类似的问题。首先,将 data-spy="scroll"和 data-target=".sidenav"属性添加到 body 标记中。当在 DOM 中添加得更深入时,它无法正常工作,导致 nav 元素位于添加属性的位置之外。

例如

<body data-spy="scroll" data-target=".sidenav" >

另一个需要注意的事项是,当导航切换到固定位置时,它会更改 a、b、c、d 部分距顶部的偏移量,因此之前计算的各部分的位置不再准确.

以下是添加到 body 标记的属性的示例:http://jsfiddle.net/b8JkE/50/

关于twitter-bootstrap - bootstrap scrollspy sidenav 不工作 - 最后一项选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13179119/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com