Add a hashchange listener for TOC viewing
This commit is contained in:
parent
1ad3abf156
commit
adc9dbf75f
1 changed files with 8 additions and 0 deletions
|
|
@ -321,3 +321,11 @@ tocToggle.addEventListener("click", () => {
|
|||
layout?.classList.toggle("toc-hidden");
|
||||
document.body.classList.toggle("toc-collapsed");
|
||||
});
|
||||
|
||||
// scroll TOC item into view when navigating via hash
|
||||
window.addEventListener("hashchange", () => {
|
||||
const id = location.hash.slice(1);
|
||||
if (id) {
|
||||
tocList?.querySelector(`a[href="#${id}"]`)?.scrollIntoView({ block: "nearest" });
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue