我一直在尝试让 scroll spy 在我的 bootstrap 网站上工作,但我无法让它工作。我遇到的问题是,无论我滚动到哪里,滚动都没有效果。你可以看到我在做什么here .
我已经执行了所有需要的步骤,即下面是 body 标签
<body data-spy="scroll" data-target="#top-fixed-nav">
导航也在那里:
<ul class="nav" id="top-fixed-nav">
<li>
<a href="#home">Home</a>
</li>
<li class="">
<a href="#about">About</a>
</li>
<li class="">
<a href="#howto">How to Use?</a>
</li>
<li class="">
<a href="#contact">Contact</a>
</li>
</ul>
也调用了 scrollspy。
$('#top-fixed-nav').scrollspy();
任何人都可以看看并指出我在这里忽略或做错了什么。
最佳答案
Docs说:
To easily add scrollspy behavior to your topbar navigation, add
data-spy="scroll"
to the element you want to spy on ( most typically this would be the<body>
). Then add thedata-target
attribute with the ID or class of the parent element of any Bootstrap.nav
component.
您发布的代码无法正常工作,因为您在监视 #top-fixed-nav
(滚动事件)。
关于javascript - 使用 twitter bootstrap scroll spy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17907132/