jgallen23 / toc

Table of Contents Plugin
http://projects.jga.me/toc/
MIT License
531 stars 111 forks source link

Last item in TOC keeps getting set to active #26

Open legos opened 11 years ago

legos commented 11 years ago

I'm not sure what's going on but the last item in my TOC keeps being set as the active one when I scroll to the top of the page. Any thoughts?

scinart commented 10 years ago

with following hackings, I managed to let it working, at least it seems to work on my github.io I'm not quite familiar with jQuery though.

  for (var i = 0, c = headingOffsets.length; i < c; i++) {
    if (headingOffsets[i] >= top) {
      $('li', self).removeClass(activeClassName);
<<<<
      highlighted = $('li:eq('+(i-1)+')', self).addClass(activeClassName);
====
      highlighted = $('li:eq('+((i-1)<0?0:i-1)+')', self).addClass(activeClassName);
>>>>
      opts.onHighlight(highlighted);
      break;
    }
  }
<<<<
====
  // added by scinart.
  if (i == headingOffsets.length)
  {
    $('li', self).removeClass(activeClassName);
    highlighted = $('li:eq('+(i-1)+')', self).addClass(activeClassName);
    opts.onHighlight(highlighted);
  }
>>>>