Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion apps/svelte.dev/src/routes/docs/[...path]/OnThisPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,30 @@
}
</script>

<svelte:window onscroll={update} onhashchange={() => (current = location.hash.slice(1))} />
<svelte:window
onscroll={update}
onhashchange={() => {
current = location.hash.slice(1);
// Correct scroll position if needed
const active = [...headings.values()].find((entry) => entry.id === current);
if (active) {
const { top, bottom } = active.getBoundingClientRect();
const min = 100;
const max = window.innerHeight - 100;
if (top > max) {
window.scrollBy({
top: top - max,
left: 0
});
} else if (bottom < min) {
window.scrollBy({
top: bottom - min,
left: 0
});
}
}
}}
/>

<aside class="on-this-page">
<label>
Expand Down
Loading