Skip to content

Commit

Permalink
fix: broken scroll-to-top button
Browse files Browse the repository at this point in the history
  • Loading branch information
Attacktive committed Feb 25, 2024
1 parent 0d03c01 commit 3650749
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "witchspring-r-editor",
"version": "1.1.0",
"version": "1.1.1",
"private": true,
"type": "module",
"scripts": {
Expand Down
14 changes: 0 additions & 14 deletions src/components/Main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,8 @@
files = undefined;
saveData.reset();
};
let toShowTopButton: boolean;
const onScroll = () => {
toShowTopButton = document?.documentElement.scrollTop > 50;
};
const scrollToTop = () => document?.documentElement.scrollIntoView();
</script>

<svelte:window on:scroll={onScroll}/>

{#if toShowSpinner}
<div class="fixed w-full h-full bg-transparent">
<Img src={nyancat} class="h-full"/>
Expand Down Expand Up @@ -144,8 +135,3 @@
</TabItem>
</Tabs>
</div>
<div class="fixed bottom-0 w-full">
{#if toShowTopButton}
<Button on:click={scrollToTop}>△</Button>
{/if}
</div>
22 changes: 16 additions & 6 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
<script>
<script lang="ts">
import "$/app.css";
import { Footer, FooterLink, FooterLinkGroup, Textarea } from "flowbite-svelte";
import { Button, Footer, FooterLink, FooterLinkGroup, Textarea } from "flowbite-svelte";
import { saveDataJson } from "$store/save-data";
import github from "$lib/assets/github.svg";
let mainElement: HTMLElement;
let toShowTopButton: boolean;
const onScroll = () => {
toShowTopButton = mainElement.scrollTop > 50;
};
const scrollToTop = () => mainElement.scrollTo(0, 0);
</script>

<div class="flex flex-col h-screen overflow-hidden">
<header class="w-full text-center">
<h1 class="text-4xl">WitchSpring R Editor</h1>
<div class="px-3 flex flex-col h-screen overflow-hidden">
<header class="w-full my-5">
<h1 class="text-center text-4xl">WitchSpring R Editor</h1>
{#if toShowTopButton}
<Button class="fixed right-10" on:click={scrollToTop}>△</Button>
{/if}
</header>
<main class="flex-1 overflow-y-scroll">
<main bind:this={mainElement} class="flex-1 overflow-y-scroll" on:scroll={onScroll}>
<slot/>
</main>
<Footer class="w-full">
Expand Down

0 comments on commit 3650749

Please sign in to comment.