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>
import { onMount } from 'svelte'
import { stores } from '@sapper/app'
import Nav from '../components/Nav.svelte'
export let segment
let wrapper
let main
function resize() {
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(() => {
const listener = window.addEventListener('resize', resize)
resize()
@ -45,7 +59,7 @@
<div bind:this={wrapper}>
<Nav {segment} />
<main>
<main bind:this={main}>
<slot />
</main>
</div>