Skip to content

Instantly share code, notes, and snippets.

@mlebkowski
Last active December 20, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlebkowski/6061656 to your computer and use it in GitHub Desktop.
Save mlebkowski/6061656 to your computer and use it in GitHub Desktop.
function getPosY(e) {
var top = 0;
while (e) {
top += parseInt(e.offsetTop) || 0;
e = e.offsetParent;
}
return top;
}
var lastTop = null;
var iAmHere;
setInterval(function () {
var c = 0,
as = tocDiv.getElementsByTagName('a'),
top = parseInt(window.pageYOffset || window.scrollY || document.documentElement.scrollTop) || 0;
if (top != lastTop) {
for (var a, i = 0; a = as[i]; i++) {
var e, hash = a.href.substr(a.href.indexOf('#') +1);
if (e = document.getElementById(hash)) {
if ((getPosY(e) <= top+100)) {
c = i;
}
}
}
if (iAmHere) iAmHere.id = ''; (iAmHere = as[c]).id = 'here';
strzalka.style.top = 0 + tocHeight / as.length * c + 'px';
}
lastTop = top;
}, 400);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment