diff --git a/sites/svelte.dev/src/routes/docs/[slug]/OnThisPage.svelte b/sites/svelte.dev/src/routes/docs/[slug]/OnThisPage.svelte index 8fa1a46aa0..db8c92361c 100644 --- a/sites/svelte.dev/src/routes/docs/[slug]/OnThisPage.svelte +++ b/sites/svelte.dev/src/routes/docs/[slug]/OnThisPage.svelte @@ -24,10 +24,12 @@ let positions = []; /** @type {HTMLElement} */ - let containerEl; + let container_el; let show_contents = false; + let glider_index = 0; + onMount(async () => { await document.fonts.ready; @@ -86,12 +88,14 @@ ); } + $: glider_index = details.sections.findIndex(({ slug }) => hash.replace('#', '') === slug); + afterUpdate(() => { // bit of a hack — prevent sidebar scrolling if // TOC is open on mobile, or scroll came from within sidebar if (show_contents && window.innerWidth < 832) return; - const active = containerEl.querySelector('.active'); + const active = container_el.querySelector('.active'); if (active) { const { top, bottom } = active.getBoundingClientRect(); @@ -100,13 +104,13 @@ const max = window.innerHeight - 200; if (top > max) { - containerEl.scrollBy({ + container_el.scrollBy({ top: top - max, left: 0, behavior: 'smooth', }); } else if (bottom < min) { - containerEl.scrollBy({ + container_el.scrollBy({ top: bottom - min, left: 0, behavior: 'smooth', @@ -118,7 +122,7 @@ select($page.url)} /> -