Skip to content

Commit d8bc812

Browse files
committed
fix left nav
1 parent 485064f commit d8bc812

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

js/fix-toc-scroll.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ document.addEventListener("DOMContentLoaded", () => {
1616
});
1717
}
1818

19-
// Update active TOC link
19+
// Update right TOC only (left nav will not change)
2020
function updateTOC() {
21-
const headings = document.querySelectorAll('.md-content__inner h1, .md-content__inner h2, .md-content__inner h3');
22-
if (headings.length === 0) {
23-
return;
24-
}
25-
const scrollPosition = window.scrollY + SCROLL_OFFSET + 5; // small buffer
21+
const headings = document.querySelectorAll('.md-content__inner h1, .md-content__inner h2, .md-content__inner h3');
22+
if (headings.length === 0) return;
2623

24+
const scrollPosition = window.scrollY + SCROLL_OFFSET + 5; // small buffer
2725
let activeHeading = headings[0];
2826

2927
for (const heading of headings) {
@@ -34,15 +32,7 @@ document.addEventListener("DOMContentLoaded", () => {
3432
}
3533
}
3634

37-
// Left nav
38-
document.querySelectorAll(TOC_SELECTOR_LEFT).forEach(link => {
39-
link.classList.remove('md-nav__link--active');
40-
if (link.getAttribute('href') === `#${activeHeading.id}`) {
41-
link.classList.add('md-nav__link--active');
42-
}
43-
});
44-
45-
// Right nav (optional)
35+
// Right nav only
4636
document.querySelectorAll(TOC_SELECTOR_RIGHT).forEach(link => {
4737
link.classList.remove('md-nav__link--active');
4838
if (link.getAttribute('href') === `#${activeHeading.id}`) {
@@ -67,9 +57,6 @@ document.addEventListener("DOMContentLoaded", () => {
6757
});
6858
});
6959

70-
// Update TOC on scroll
60+
// Update TOC on scroll (only right nav)
7161
window.addEventListener('scroll', updateTOC);
72-
73-
// Triple verification: check periodically in case of delayed rendering
74-
setInterval(updateTOC, 500);
7562
});

0 commit comments

Comments
 (0)