scroll top

This commit is contained in:
cupcakearmy 2020-11-11 22:25:30 +01:00
parent 29a584f6b9
commit 44714c5c0c
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9

View File

@ -1,15 +1,29 @@
<script> <script>
import { onMount } from 'svelte' import { onMount } from 'svelte'
import { stores } from '@sapper/app'
import Nav from '../components/Nav.svelte' import Nav from '../components/Nav.svelte'
export let segment export let segment
let wrapper let wrapper
let main
function resize() { function resize() {
wrapper.style.height = `${window.innerHeight}px` wrapper.style.height = `${window.innerHeight}px`
} }
const { page } = stores()
let last = ''
$: {
const { host, path } = $page
const full = host + path
if (last !== full) {
last = full
if (main) setTimeout(() => (main.scrollTop = 0), 150)
}
}
onMount(() => { onMount(() => {
const listener = window.addEventListener('resize', resize) const listener = window.addEventListener('resize', resize)
resize() resize()
@ -45,7 +59,7 @@
<div bind:this={wrapper}> <div bind:this={wrapper}>
<Nav {segment} /> <Nav {segment} />
<main> <main bind:this={main}>
<slot /> <slot />
</main> </main>
</div> </div>