The last section on a page will remain unselected if the bottom of the page is reached before the top of that section (e.g. the section's height is small).
We can force the last section to be selected when the bottom of the page is reached using the following few lines of code added to the 'getCurrrentSection' method (right before the return statement)
// get the last section if we reached the bottom of the page
// before reaching the last section top
var pageBottom = $(document).height() - $(window).height();
if ( scrollPos == pageBottom ){
var numberOfLinks = this.$links.length;
if ( numberOfLinks > 0 ){
section = this.$links[ numberOfLinks - 1].hash;
}
}
// The current section or the first link if it is found
return section || ((this.$links.length===0) ? (null) : (this.$links[0].hash));
please consider adding this to the next version of the plugin
This works perfectly! Thanks for this tip @tomasvorobjov . And yes please, @ChrisWojcik , I second the thought that this would be really nice to have in the plugin.
UPDATE: one small issue actually remains. If you click a menu item that isn't the last one, but it take you to the bottom of the viewport, then this fix doesn't help as you have to scroll again down for it to activate, but of course that can't happen now.
The last section on a page will remain unselected if the bottom of the page is reached before the top of that section (e.g. the section's height is small).
We can force the last section to be selected when the bottom of the page is reached using the following few lines of code added to the 'getCurrrentSection' method (right before the return statement)
please consider adding this to the next version of the plugin
Thank you