tscanlin / tocbot

Build a table of contents from headings in an HTML document.
MIT License
1.39k stars 115 forks source link

BUG: Links don't highlight on short pages #277

Closed pacollins closed 2 years ago

pacollins commented 2 years ago

When the page ends before all headings reach the top of the window, those headings do not highlight properly. I assume that you are aware of this because your documentation site has a margin: 95vh on the main content.

Is there any solution or possible solution to this problem? The library is fantastic, but this bug prevents it from being as polished as it could be.

A possible solution with not real code?

if ( (pageBottom - headingPosition) < windowHeight) {
  highlight when headingPosition = (windbottom window 
}

Example

if ( (1600 - 1200) < 1000 ) {
  highlight when heading is at 600 of window 
}
if ( (1600 - 1400) < 1000 ) {
  highlight when heading is at 800 of window
}

This would make items highlight progressively faster if they won't ever have the opportunity to reach the top of the window.

tscanlin commented 2 years ago

Hey, thanks for your interest. I can't really think of any ways to handle this besides having the bottom margin so that you can actually scroll to all of the headings (as you mentioned the docs do). If you have multiple headings that don't have much content at the end, then determining which to show as highlighted is not intuitive. Trying to address this would add extra code and complexity for something I think is a pretty minor edge case.