I'm trying to create a site using Bootstrap 3 RC1 with Scrollspy. My web page is pretty simple right now, and is essentially set up like this:
<html>
<head>
<!-- Head stuff here -->
</head>
<body>
<section id="section_1" data-spy="scroll">
<!-- stuff in here -->
</section>
<section id="section_2" data-spy="scroll">
<!-- stuff in here -->
</section>
<section id="section_3" data-spy="scroll">
<!-- stuff in here -->
</section>
<JScripts here ... />
</body>
</html>
I've initialized Scrollspy by calling $("section").scrollspy()
and I've set up an event handler like this:
$("section").on("activate", function(e) {
// do stuff
});
My problem is that this activate
event never gets fired. Does anyone know why it's not working? I noticed that all the tutorials use a navbar for highlighting the current section, but I don't really want a navbar.
Your markup for scrollspy is a little off. Scrollspy may not be firing which is why you are probably not getting any results. In my experience it's much easier to user data attributes to initiate scrollspy. And I haven't read one report of it working if you append the scroll listener to any other element than the body itself.
You should apply them to your body tag like this.
Also, you need to make sure that your navigation structure is like this: