(7 intermediate revisions by the same user not shown) | |||
Line 21: | Line 21: | ||
document.body.classList.toggle('nav-in'); | document.body.classList.toggle('nav-in'); | ||
}); | }); | ||
+ | |||
+ | var mul = ul.getElementsByClassName('multiple'); | ||
+ | for (var i = 0; i < mul.length; i++) { | ||
+ | var m = mul[i]; | ||
+ | m.addEventListener('click', function () { | ||
+ | for (var j = 0; j < mul.length; j++) { | ||
+ | var r = mul[j]; | ||
+ | r.classList.remove('clicked'); | ||
+ | } | ||
+ | |||
+ | this.classList.add('clicked'); | ||
+ | }); | ||
+ | } | ||
ul.addEventListener('mouseover', over); | ul.addEventListener('mouseover', over); | ||
Line 26: | Line 39: | ||
var as = document.getElementById('toc').getElementsByTagName('a'); | var as = document.getElementById('toc').getElementsByTagName('a'); | ||
− | for (var | + | for (var i = 0; i < as.length; i++) { |
+ | var a = as[i]; | ||
a.addEventListener('click', function () { | a.addEventListener('click', function () { | ||
− | for (var | + | for (var j = 0; j < as.length; j++) { |
+ | var oa = as[j]; | ||
oa.classList.remove('active'); | oa.classList.remove('active'); | ||
} | } | ||
Line 36: | Line 51: | ||
} | } | ||
+ | // thanks to wikimedia replacing two ampersands with && | ||
+ | function and(a, b) { | ||
+ | if (a == true) { | ||
+ | if (b == true) { | ||
+ | return true; | ||
+ | } | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
− | + | function setScrollyThing() { | |
var activeA = null; | var activeA = null; | ||
− | for (var | + | var nextIsActive = false; |
+ | for (var i = 0; i < as.length; i++) { | ||
+ | var a = as[i]; | ||
a.classList.remove('active'); | a.classList.remove('active'); | ||
+ | |||
+ | if (nextIsActive || and(!a.parentElement.classList.contains('toclevel-1'), !activeA)) { | ||
+ | activeA = a; | ||
+ | nextIsActive = false; | ||
+ | continue; | ||
+ | } | ||
var id = a.href.replace(/.+?#/, ''); | var id = a.href.replace(/.+?#/, ''); | ||
Line 52: | Line 84: | ||
var active = y < 200; | var active = y < 200; | ||
if (active) { | if (active) { | ||
+ | if (a.parentElement.classList.contains('toclevel-1')) nextIsActive = true; | ||
activeA = a; | activeA = a; | ||
} | } | ||
} | } | ||
− | |||
activeA.classList.add('active'); | activeA.classList.add('active'); | ||
− | }); | + | } |
+ | |||
+ | document.addEventListener('scroll', setScrollyThing); | ||
+ | setScrollyThing(); | ||
}); | }); | ||
</script> | </script> | ||
</html> | </html> |
Latest revision as of 17:18, 17 October 2018