Scroll TOC list when clicking a letter

This commit is contained in:
Jared Miller 2025-12-26 07:56:20 -05:00
parent 180832b84c
commit 9b0debd0ba
No known key found for this signature in database
2 changed files with 10 additions and 0 deletions

View file

@ -52,6 +52,15 @@ Array.from(firstByLetter.entries())
tocLetters?.appendChild(link); tocLetters?.appendChild(link);
}); });
// scroll TOC list when clicking a letter
tocLetters?.addEventListener("click", (e) => {
if (e.target.tagName !== "A") return;
const href = e.target.getAttribute("href");
if (!href) return;
const tocLink = tocList?.querySelector(`a[href="${href}"]`);
tocLink?.scrollIntoView({ block: "start" });
});
const searchInput = document.getElementById("toc-search"); const searchInput = document.getElementById("toc-search");
let searchTimeout; let searchTimeout;
searchInput?.addEventListener("input", (event) => { searchInput?.addEventListener("input", (event) => {

View file

@ -140,6 +140,7 @@ body {
padding: 6px 8px; padding: 6px 8px;
border-radius: 10px; border-radius: 10px;
display: block; display: block;
scroll-margin-top: 1rem;
transition: transition:
background 0.2s ease, background 0.2s ease,
color 0.2s ease; color 0.2s ease;