davist11/jQuery-One-Page-Nav — Issue #5: Problem with Out of Order Menu Items
Author: neilo4171
Created: 2011-10-28 04:22:52+00:00
State: open

Thanks for the great plugin.

I have found a problem when menu items are out of order. For example if the last menu item was __Top Of The Page__, then the last menu item would always revert to current when manually scrolling, this would also happen when clicking the second last menu item.

In my implementation I have fixed this by altering getPositions and getSection to use the bottom as well as the top of the page section, as below:

```javascript
onePageNav.getPositions = function($this, o) {
$this.find('a').each(function() {
var linkHref = $(this).attr('href'),
divPos = $(linkHref).offset(),
topPos = divPos.top

onePageNav.sections[linkHref.substr(1)] = {
top: Math.round(topPos),
bottom: Math.round(topPos)+$(linkHref).height()
};
});
};

onePageNav.getSection = function(windowPos) {
var returnValue = '',
windowCentre = Math.round($(window).height() / 2) + windowPos;

for(var section in onePageNav.sections) {
if (windowCentre >= onePageNav.sections[section].top &&
windowCentre < onePageNav.sections[section].bottom) {
return section;
}
}
};
```

Hope this help.