File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 2424 import { Head } from ' svead'
2525 import { onMount } from ' svelte'
2626 import { writable } from ' svelte/store'
27+ import BackToTop from ' ./back-to-top.svelte'
2728
2829 // Head variables
2930 let title = ' This is SvelteKit embed'
6970
7071<!-- cSpell:ignore yyoood,Zokm,Zrzbx -->
7172
73+ <BackToTop />
74+
7275# SvelteKit Embed
7376
7477This is a collection of embed components I use on a regular basis
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import { fly } from ' svelte/transition'
3+
4+ let showScrollButton = false
5+
6+ function scrollToTop() {
7+ window .scrollTo ({
8+ top: 0 ,
9+ behavior: ' smooth' ,
10+ })
11+ }
12+
13+ function handleScroll() {
14+ showScrollButton = window .pageYOffset > 0
15+ }
16+ </script >
17+
18+ <svelte:window on:scroll ={handleScroll } />
19+
20+ {#if showScrollButton }
21+ <button
22+ on:click ={scrollToTop }
23+ transition:fly ={{ y : 200 , duration : 300 }}
24+ class =" fixed bottom-8 right-8 btn btn-primary normal-case"
25+ >
26+ Back to top
27+ </button >
28+ {/if }
You can’t perform that action at this time.
0 commit comments