From 4c43e1458e5b7a610ef140bc32fb3a94b8cbefb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sun, 21 Nov 2021 22:43:24 +0100 Subject: [PATCH] Don't scroll back to top when changing Photos and Shop products pages --- src/routes/__layout.svelte | 9 ++++----- src/utils/functions/index.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index 6ec0633..7c2297c 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -3,6 +3,7 @@ import { navigating, page } from '$app/stores' import { onMount, setContext } from 'svelte' import { pageLoading } from '$utils/stores' + import { scrollToTop } from '$utils/functions' import { DURATION } from '$utils/contants' import '$utils/polyfills' // Components @@ -34,12 +35,10 @@ // Scroll back to top between page transitions setTimeout(() => { - // scrollToTop() - // Disable scroll when changing filters on /photos? - if (!$page.query.get('country')) { - window.scrollTo(0,0) + // Disable scroll when changing filters on /photos and shop? + if (!$page.query.get('country') && !$page.path.includes('/shop/poster')) { + scrollToTop() } - }, DURATION.PAGE_OUT * 1.5) } }) diff --git a/src/utils/functions/index.ts b/src/utils/functions/index.ts index 16a9619..56eb8a2 100644 --- a/src/utils/functions/index.ts +++ b/src/utils/functions/index.ts @@ -117,4 +117,18 @@ export const getPosition = (node, scope?: HTMLElement) => { top: offsetTop, left: offsetLeft } +} + + +/** + * Scroll back to top after page transition + */ +export const scrollToTop = (delay?: number) => { + const scroll = () => window.scrollTo(0,0) + + if (delay && delay > 0) { + setTimeout(scroll, delay) + } else { + scroll() + } } \ No newline at end of file