Scroll back to top when transition out is finished

Potentially the end of nightmares for page transitions with `sveltekit:noscroll`?
This commit is contained in:
2022-03-21 14:05:54 +01:00
parent 91510df410
commit 7c369794c1

View File

@@ -7,22 +7,14 @@
export let name: string
onMount(async () => {
// Disable when changing filters on /photos and shop?
if (!$page.url.searchParams.get('country') && !$page.url.pathname.includes('/shop')) {
await tick()
setTimeout(() => {
// Scroll back to top between page transitions
scrollToTop()
}, DURATION.PAGE_DELAY)
}
})
$: doNotScroll = !$page.url.searchParams.get('country') && !$page.url.pathname.includes('/shop')
</script>
<main class={name}
in:fade={{ duration: DURATION.PAGE_IN, delay: DURATION.PAGE_DELAY }}
out:fade={{ duration: DURATION.PAGE_OUT }}
on:outroend={() => doNotScroll && scrollToTop()}
>
<slot />
</main>