fix Issue #1 mobile ToC highlight
This commit is contained in:
1 parent
1d667a0aaf
commit
4b7a12fafa
1 file changed
+10
-6
+10
-6
@@ -262,12 +262,16 @@
|
|||||||
var top = h.getBoundingClientRect().top + scrollY;
|
var top = h.getBoundingClientRect().top + scrollY;
|
||||||
if (top <= threshold) active = h;
|
if (top <= threshold) active = h;
|
||||||
});
|
});
|
||||||
var links = tocNav.querySelectorAll('.toc-link');
|
// Document-wide, not scoped to tocNav: the mobile drawer holds a clone
|
||||||
Array.prototype.forEach.call(links, function (a) { a.classList.remove('active'); });
|
// of this list and needs the same highlight. Match on .toc-link so the
|
||||||
if (active) {
|
// heading "#" anchors, which share the href, aren't marked active; and
|
||||||
var link = tocNav.querySelector('a[href="#' + active.id + '"]');
|
// compare the href rather than building a selector from the id, which
|
||||||
if (link) link.classList.add('active');
|
// would throw on a hand-written id containing a quote.
|
||||||
}
|
var links = document.querySelectorAll('.toc-link');
|
||||||
|
var href = active ? '#' + active.id : null;
|
||||||
|
Array.prototype.forEach.call(links, function (a) {
|
||||||
|
a.classList.toggle('active', a.getAttribute('href') === href);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('scroll', updateActive, { passive: true });
|
window.addEventListener('scroll', updateActive, { passive: true });
|
||||||
|
|||||||
Reference in new issue
Block a user