2

I'm trying to use scrollspy for my fixed header nav, and it works correctly when I initially load the page.

However, if I click one of the links in the header to jump to that section, that link that I just clicked will no longer show as active when I scroll around the page past it. All the links behave this way, I don't know why they will work initially but then stop working once clicked.

<body data-spy="scroll" data-target="#myNav">
<header class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#home">Example Brand</a>
    </div>

  <div id="myNav" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li><a href="#home">Home</a></li>
        <li><a href="#course">Courses</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </div><!--/.nav-collapse -->
</div>

<h1 id="home">Home Heading</h1>

...

<div id="course" class="course-header">Courses</div>

...

<h2 id="contact">Contact Us</h2>

Also if I refresh the page, it goes back to working correctly again.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.