Skip to content

Commit

Permalink
fix: horrifically stupid bug with scrolling to IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
PuruVJ committed Jun 22, 2023
1 parent 2f656d2 commit 637073a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-games-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/site-kit': patch
---

fix: horrifically stupid bug with scrolling to IDs
28 changes: 21 additions & 7 deletions packages/site-kit/src/lib/docs/DocsOnThisPage.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
import { browser } from '$app/environment';
import { afterNavigate } from '$app/navigation';
import { base } from '$app/paths';
import { page } from '$app/stores';
Expand Down Expand Up @@ -36,6 +37,26 @@
highlight();
});
$: pathname = $page.url.pathname;
$: {
pathname;
emulate_autoscroll();
}
async function emulate_autoscroll() {
if (browser) {
const hash = $page.url.hash.replace(/^#/, '');
const el = document.getElementById(hash);
console.log(el);
await tick();
el?.scrollIntoView({ behavior: 'auto', block: 'start' });
}
}
afterNavigate(() => {
update();
highlight();
Expand All @@ -55,13 +76,6 @@
return heading.getBoundingClientRect().top - parseFloat(style.scrollMarginTop) - top;
});
height = window.innerHeight;
const hash = $page.url.hash.replace(/^#/, '');
const el = document.getElementById(hash);
await tick();
el?.scrollIntoView({ behavior: 'auto', block: 'start' });
}
function highlight() {
Expand Down

0 comments on commit 637073a

Please sign in to comment.