Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Bootstrap ScrollSpy doesn't work

I'm trying the ScrollSpy Bootstrap plugin, but it's not working properly. See the code below, it always highlight the last item.

http://jsfiddle.net/bRYMC/

<nav id="navbar">
  <ul class="nav">
    <li><a href="#page1">Page 1</a></li>
    <li><a href="#page2">Page 2</a></li>
    <li><a href="#page3">Page 3</a></li>
    <li><a href="#page4">Page 4</a></li>
    <li><a href="#page5">Page 5</a></li>
  </ul>
</nav>

<div data-spy="scroll">
  <section id="page1" class="page">
    <h1>Page 1</h1>
  </section>

  <section id="page2" class="page">
    <h1>Page 2</h1>
  </section>

  <section id="page3" class="page">
    <h1>Page 3</h1>
  </section>

  <section id="page4" class="page">
    <h1>Page 4</h1>
  </section>

  <section id="page5" class="page">
    <h1>Page 5</h1>
  </section>
</div>

​Can you help me?

like image 982
Caio Tarifa Avatar asked Oct 11 '12 15:10

Caio Tarifa


Video Answer


1 Answers

Set the data-spy="scroll" on the body tag and it should work. Please check the updated jsFiddle.

like image 86
Syed Aslam Avatar answered Oct 04 '22 08:10

Syed Aslam