Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

twitter Bootstrap Scrollspy highlight final element

I'm building a single page website with the top bar navigation linking to different sections on the page. I've linked it up using Scrollspy as <body data-spy="scroll" data-offset="50" id="home">. That works great. Each section is highlighted in the navigation.

The problem lies with the final section. Because it is a short section and does not fill the entire page the id="contact" is never reached, and therefore the navigation element is not highlighted.

I notice that on the bootstrap examples page when you reach the final element it is highlighted before its id is reached - yet the id is at the top of the section just like all the other sections.

I've had a look through the custom application.js file but don't see anything relating to scrollspy behaviour.

Can anyone shed any light on it?

like image 216
deadlyhifi Avatar asked Mar 23 '12 14:03

deadlyhifi


2 Answers

Just increase your data-offset attribute to something larger like 500, like so:

<body data-spy="scroll" data-offset="500" id="home">

The bootstrap demo works fine because it is also offsetting the height of the subnav, along with the 50px offset that is given on the data attribute.

like image 143
Andres Ilich Avatar answered Oct 05 '22 18:10

Andres Ilich


I have a workaround. On line 40 of twitter's scrollspy JS, you'll see:

this.process()

Just remove that. This runs the process method in a clever attempt to start 'er up. But this is processed when you scroll anyways, so just remove it and you should be good.

like image 21
Tommy Marshall Avatar answered Oct 05 '22 19:10

Tommy Marshall