ChrisWojcik / single-page-nav

jQuery plugin that provides smooth scrolling and advanced navigation for single page websites.
http://chriswojcik.net/demos/single-page-nav/
161 stars 74 forks source link

The last section remains unselected if the document bottom is reached #13

Closed scibuff closed 7 years ago

scibuff commented 10 years ago

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

Thank you

onetrev commented 10 years ago

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.