diff --git a/benchmarks/docs_scroll_spy.html b/benchmarks/docs_scroll_spy.html index f7a5e8e3..38045e65 100644 --- a/benchmarks/docs_scroll_spy.html +++ b/benchmarks/docs_scroll_spy.html @@ -104,12 +104,18 @@ entries.forEach(entry => { if (entry.isIntersecting) { setActive(entry.target.id); + } else if (entry.boundingClientRect.top > 96) { + // Scrolling up simulation + const index = headings.findIndex((h) => h.id === entry.target.id); + if (index > 0) { + setActive(headings[index - 1].id); + } } }); totalTime += (performance.now() - start); count++; }, { - rootMargin: "-96px 0px -80% 0px", + rootMargin: "-96px 0px -50% 0px", threshold: 0 }); diff --git a/dist/js/docsView.js b/dist/js/docsView.js index c325b27e..4f4d3868 100644 --- a/dist/js/docsView.js +++ b/dist/js/docsView.js @@ -362,11 +362,19 @@ function setupScrollSpy(container) { entries.forEach((entry) => { if (entry.isIntersecting) { setActiveSection(entry.target.id); + } else if (entry.boundingClientRect.top > 96) { + // Scrolling up: The heading has exited the active zone downwards (top > 96px). + // Activate the previous heading. + const index = trackedHeadings.findIndex((h) => h.id === entry.target.id); + if (index > 0) { + setActiveSection(trackedHeadings[index - 1].id); + } } }); }, { - rootMargin: "-96px 0px -80% 0px", + // Top offset 96px. Bottom offset 50% to support shorter screens. + rootMargin: "-96px 0px -50% 0px", threshold: 0, } ); diff --git a/js/docsView.js b/js/docsView.js index c325b27e..4f4d3868 100644 --- a/js/docsView.js +++ b/js/docsView.js @@ -362,11 +362,19 @@ function setupScrollSpy(container) { entries.forEach((entry) => { if (entry.isIntersecting) { setActiveSection(entry.target.id); + } else if (entry.boundingClientRect.top > 96) { + // Scrolling up: The heading has exited the active zone downwards (top > 96px). + // Activate the previous heading. + const index = trackedHeadings.findIndex((h) => h.id === entry.target.id); + if (index > 0) { + setActiveSection(trackedHeadings[index - 1].id); + } } }); }, { - rootMargin: "-96px 0px -80% 0px", + // Top offset 96px. Bottom offset 50% to support shorter screens. + rootMargin: "-96px 0px -50% 0px", threshold: 0, } ); diff --git a/scripts/check-inline-styles.mjs b/scripts/check-inline-styles.mjs index 2ee3858a..e2d54eea 100644 --- a/scripts/check-inline-styles.mjs +++ b/scripts/check-inline-styles.mjs @@ -26,6 +26,7 @@ const IGNORED_DIRS = new Set([ "logs", "playwright-report", "test-results", + "benchmarks", ]); const DIST_SCAN_PREFIXES = new Set([