javascript - 使用 twitter bootstrap scroll spy

标签 javascript jquery twitter-bootstrap scroll scrollspy

我一直在尝试让 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/

相关文章:

javascript - 具有多个输入的 .form-group 上的 jQuery 验证

javascript - 使用 Firefox native 消息进行异步 webRequest.onBeforeRequest URL 检查

node.js - 正文解析器错误。

javascript - Phonegap 中的 Jquery ajax 调用到 RESTful API

html - 无法删除上边距

javascript - PHP $_GET 无法与 JQuery Mobile 一起使用

jQuery .toggle() 不适用于 IE 中的 TRs

css - Bootstrap 导航栏下拉按钮

html - Bootstrap 在从 col-sm 到 col-xs 时添加了一条白线

javascript - 如何使用 JQuery 创建下拉菜单