Last active
December 20, 2015 03:09
-
-
Save mlebkowski/6061656 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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