gfranko / jquery.tocify.js

A jQuery Table of Contents plugin that can be themed with Twitter Bootstrap or jQueryUI.
http://gregfranko.com/jquery.tocify.js/
MIT License
927 stars 217 forks source link

Highlighting fails of highlights wrong item #34

Closed andrekampert closed 11 years ago

andrekampert commented 11 years ago

There are two symptoms of a problem with highlighting:

Highlighting not updated

When scrolling larger pages really fast, sometimes the highlighting is not updated due to events being skipped. This is because for some reason we never get a position within the offset, so the update is skipped entirely (line 622)

javascript if ((Math.abs($(this).offset().top - winScrollTop) < self.options.highlightOffset))


#### Highlight wrong item after clicking in toc

Sometimes, based on the structure of the page, another item is highlighted in the TOC, because after scrolling tocify consider an item on top within the highlightOffset. However, the item below is closer, so should be highlighted instead of the first item within the highlightOffset.
#### Proposed solution

Instead of the first element within the highlightOffset, use the one closest to the current position. I've made this improvement in a fork and will create a pull request.
gfranko commented 11 years ago

@andrekampert I'm really looking forward to your PR! Just make sure to send it to the dev branch =)

andrekampert commented 11 years ago

I just pushed the changes and created a PR. Nice work BTW, I really like the way this menu works.