File size: 882 Bytes
c479a59
 
 
 
 
 
 
 
 
b1a4d81
 
 
 
 
 
 
 
 
 
c479a59
 
 
b1a4d81
c479a59
 
 
b1a4d81
 
 
c479a59
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<script lang="ts">
	import { browser } from "$app/environment";
  import Icon from "@iconify/svelte";

  const goTop = () => {
    const element = document.getElementById('app');
    element?.scrollTo({ top: 0, behavior: 'smooth' });
  }

  let visible = false;

  if (browser) {
    const element = document.getElementById('app');
    element?.addEventListener('scroll', () => {
      const scroll = element?.scrollTop ?? 0;
      visible = scroll > 100;
    });
  }

</script>

<button
  class="rounded-full text-sm text-neutral-950 font-semibold px-3 py-1 bg-white shadow-lg brightness-90 transition-all duration-200 hover:brightness-110 fixed bottom-8 right-8 flex items-center gap-1.5 justify-center z-10"
  class:opacity-0={!visible}
  class:pointer-events-none={!visible}
  on:click={goTop}
  >
  <Icon icon="foundation:arrow-up" class="w-4 h-4" />
  Go back to top
</button>