Skip to content

Commit

Permalink
✨ Added scrolling to top after navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
nwrenger committed Aug 1, 2024
1 parent dbdb22c commit f82f0e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
@apply border-border;
}
body {
@apply !overflow-y-scroll bg-gradient-conic from-red-800 via-background to-blue-800 text-foreground;
@apply bg-gradient-conic from-red-800 via-background to-blue-800 text-foreground;
}
body {
@apply cursor-none;
Expand Down
15 changes: 11 additions & 4 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,19 @@
}
}
export let data;
let mounted = false;
onMount(() => (mounted = true));
export let data;
$: pathname = data.pathname;
let isTouchDevice = false;
let mounted = false;
let div: HTMLDivElement | undefined;
$: if (mounted && pathname)
setTimeout(() => {
if (div) div.scrollTo({ top: 0, behavior: 'instant' });
}, 400);
onMount(() => (mounted = true));
let isTouchDevice = false;
$: if (mounted) isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
</script>

Expand All @@ -77,6 +82,8 @@
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<div
bind:this={div}
class="h-full overflow-scroll"
on:mouseleave={!isTouchDevice ? handleMouseLeave : null}
on:mouseenter={!isTouchDevice ? handleMouseEnter : null}
on:mousedown={!isTouchDevice ? handleMouseDown : null}
Expand Down

0 comments on commit f82f0e8

Please sign in to comment.