jgallen23 / toc

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

add offset, hash options, and refactor headings process #13

Open limodou opened 12 years ago

limodou commented 12 years ago
  1. Add offset option, sometimes the top position is not from 0, so this option can set the offset value from the top.
  2. Add hash option, default is false, so that user can disable hashchange process.
  3. Refactor headings process. Originally it'll save the headings positions at the initialization phrase, and after refacotring, it'll calulate immediately.
jgallen23 commented 12 years ago

The reason heading positions are cached is for performance. Every offset() call does a reflow on the document. I'll look into the other two changes.

limodou commented 12 years ago

I know what you mean. But in my case some sections may have images or the content may be changed dynamically, so I found the positions are not right when I scrolling the page, so I calaulate the position dynamically. Hope this will be helpful.

For hash option, I found when I click the link in the toc, it'll scroll to the position of related heading, but sometimes it'll "jump back a bit" then, and when I try to comment the code:

location.hash = elScrollTo;

It seems good. So I think maybe there is something wrong with it.