Using Bootstrap v3.3 w/ affix on navigation bar. Affix is working fine, but I cannot get the scrollspy to work at all. I created a fiddle here (removed affix from fiddle) to attempt to see if it wasn't something else in my JS or w/e that wasn't correct, but fiddle is not working either.
Below is example fiddle:
.product-nav.affix {
top: 0;
left: 0;
z-index: 1;
width: 100%;
background-color: #555;
}
$('.product-nav').affix({
offset: {
top: $('.hero').height()
}
});
<body data-spy="scroll" data-target="#product-nav">
<header class="hero">
<img src="http://placehold.it/400x1000" />
</header>
<div class="section gray no-padd">
<div class="container">
<!-- component -->
<div class="product-nav">
<ul class="list-inline spy-product-nav" id="product-nav">
<li><a href="#spy-key-content">Key Content</a>
</li>
<li><a href="#spy-capabilities">Capabilities</a>
</li>
<li><a href="#spy-image-carousel">Image Carousel</a>
</li>
<li><a href="#spy-video">Video</a>
</li>
<li><a href="#spy-materials">Materials</a>
</li>
<li><a href="#spy-contact-us">Contact us</a>
</li>
</ul>
</div>
<!-- ends component -->
</div>
</div>
<section id="spy-key-content">
<img src="http://placehold.it/300x500" />
<h2>Blah Blah blah</h2>
</section>
</body>
Things that I have tried:
- Removing
data-scroll
anddata-target
frombody
tag and implementing through JS instead. (ie -$('body').scrollspy.....
) - Moving id's around (instead of on the
section
, moved toh2
, etc. - Tried moving the
data-target
id,#product-nav
, to the parentdiv
of theul
instead. - Tried using classes instead of ids (for
data-target
). - Tried removing hyphens from the ids
- Checked to see if scrollspy was included in the bootstrap.js file
- Checked for console errors
I figured I've exhausted my efforts, and obviously I'm missing something simple if I cannot even get it to work on the fiddle. I am not seeing the .active
class be assigned to any of the navigation elements.
@vanburenx - your post was correct, however, the only thing I needed was to add the class,
.nav
, to the correspondingul
element.Per the boostrap documentation:
Here's an example of how you can do this. I would suggest using at least some pre-defined Bootstrap classes (esp for navigation links) otherwise you'll need to define all the states if you want your links to show a change to
active
.