Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Detecting current section fix #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions jquery.nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,22 @@
},

getSection: function(windowPos) {
var returnValue = null;
var currentSection = null;
var lastSection = null;
var windowHeight = Math.round(this.$win.height() * this.config.scrollThreshold);
var atTheBottom = windowPos >= this.docHeight - this.$win.height();
var currentPosition = windowPos + windowHeight;

for(var section in this.sections) {
if((this.sections[section] - windowHeight) < windowPos) {
returnValue = section;
if(this.sections[section] >= this.sections[lastSection || section]) {
lastSection = section;
}
if(this.sections[section] < currentPosition && this.sections[section] >= this.sections[currentSection || section]) {
currentSection = section;
}
}

return returnValue;
return atTheBottom ? lastSection : currentSection;
},

handleClick: function(e) {
Expand Down Expand Up @@ -220,4 +226,4 @@
});
};

})( jQuery, window , document );
})( jQuery, window , document );