mirror of https://github.com/VERT-sh/VERT.git
fix: save scroll position on mobile while switching pages
This commit is contained in:
parent
90ca53c2a5
commit
d013fb0084
|
@ -2,7 +2,11 @@
|
||||||
import { page } from "$app/state";
|
import { page } from "$app/state";
|
||||||
import { duration } from "$lib/animation";
|
import { duration } from "$lib/animation";
|
||||||
import VertVBig from "$lib/assets/vert-bg.svg?component";
|
import VertVBig from "$lib/assets/vert-bg.svg?component";
|
||||||
import { files, gradientColor, showGradient } from "$lib/store/index.svelte";
|
import {
|
||||||
|
files,
|
||||||
|
gradientColor,
|
||||||
|
showGradient,
|
||||||
|
} from "$lib/store/index.svelte";
|
||||||
import { quintOut } from "svelte/easing";
|
import { quintOut } from "svelte/easing";
|
||||||
import { fade } from "$lib/animation";
|
import { fade } from "$lib/animation";
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { goto } from "$app/navigation";
|
import { goto, beforeNavigate, afterNavigate } from "$app/navigation";
|
||||||
|
|
||||||
import { PUB_PLAUSIBLE_URL, PUB_HOSTNAME } from "$env/static/public";
|
import { PUB_PLAUSIBLE_URL, PUB_HOSTNAME } from "$env/static/public";
|
||||||
import { VERT_NAME } from "$lib/consts";
|
import { VERT_NAME } from "$lib/consts";
|
||||||
|
@ -20,6 +20,21 @@
|
||||||
let { children } = $props();
|
let { children } = $props();
|
||||||
let enablePlausible = $state(false);
|
let enablePlausible = $state(false);
|
||||||
|
|
||||||
|
let scrollPositions = new Map<string, number>();
|
||||||
|
|
||||||
|
beforeNavigate((nav) => {
|
||||||
|
if (!nav.from || !$isMobile) return;
|
||||||
|
scrollPositions.set(nav.from.url.pathname, window.scrollY);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterNavigate((nav) => {
|
||||||
|
if (!$isMobile) return;
|
||||||
|
const scrollY = nav.to
|
||||||
|
? scrollPositions.get(nav.to.url.pathname) || 0
|
||||||
|
: 0;
|
||||||
|
window.scrollTo(0, scrollY);
|
||||||
|
});
|
||||||
|
|
||||||
const dropFiles = (e: DragEvent) => {
|
const dropFiles = (e: DragEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
dropping.set(false);
|
dropping.set(false);
|
||||||
|
@ -49,7 +64,8 @@
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
// Enable plausible if enabled
|
// Enable plausible if enabled
|
||||||
enablePlausible = !!PUB_PLAUSIBLE_URL && Settings.instance.settings.plausible;
|
enablePlausible =
|
||||||
|
!!PUB_PLAUSIBLE_URL && Settings.instance.settings.plausible;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue