Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap scrollspy highlights last navigation link button after loading

I've built a navigation bar at the top with 5 links. At the page itself I have added 5 sections with id's according to the name after the # tag in the element. The problem is that the last navigation link button is highlighted ('active' class was added to it on runtime in the beginning although in the code itself the first navbar item is set to "active". I have the latest bootstrap version which is v2.0.4 What is wrong ?

<div class="navbar" id="MenuBar">
    <div class="topHeadContentLogo"></div>
    <ul class="nav nav-pills" id="MenuUl">
        <li class="active"><a href="#Weekly">Weekly</a></li>
        <li class=""><a href="#Post">Post</a></li>
        <li class=""><a href="#Audience">Audience</a></li>
        <li><a href="#Website">Website</a></li>
        <li><a href="#FAQ">FAQ</a></li>
    </ul>
</div>

<div id="contentDiv">
    <section id="Weekly">
        <h1>weekly</h1>
    </section>

    <section id="Post">
        <h1>Post</h1>
    </section>

    <section id="Audience">
        <h1>Audience</h1>
    </section>

    <section id="Website">
        <h1>Website</h1>
    </section>

    <section id="FAQ">
        <h1>FAQ</h1>
    </section>
</div>



$('#MenuBar').scrollspy(); after document ready
like image 413
Alon Avatar asked Jun 14 '12 11:06

Alon


2 Answers

If you have the data-spy set on the body element, make sure that the body element isn't set to height: 100%;. This was the problem in my case.

like image 95
Baris Wanschers Avatar answered Sep 20 '22 13:09

Baris Wanschers


have you added data-spy="scroll" to the <body> tag (or any other tag that's relevant)?

like image 24
Luca Avatar answered Sep 21 '22 13:09

Luca