Add a hashchange listener for TOC viewing
This commit is contained in:
parent
e7afa3173b
commit
2d4166974b
1 changed files with 8 additions and 0 deletions
|
|
@ -321,3 +321,11 @@ tocToggle.addEventListener("click", () => {
|
||||||
layout?.classList.toggle("toc-hidden");
|
layout?.classList.toggle("toc-hidden");
|
||||||
document.body.classList.toggle("toc-collapsed");
|
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