From 3ae20627cef53395d88b4b3b2fed3050e9717d38 Mon Sep 17 00:00:00 2001 From: Carter <35710697+cmintey@users.noreply.github.com> Date: Tue, 28 Nov 2023 19:21:21 -0600 Subject: [PATCH] scroll back to top on navigate (#83) --- src/routes/+layout.svelte | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 92e5e61..c7bc92d 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -33,10 +33,16 @@ showNavigationLoadingBar = true; }); - afterNavigate(() => { + afterNavigate((params) => { showNavigationLoadingBar = false; documentTitle = document?.title; disabled = titleDisabledUrls.find((url) => $page.url.pathname === url) !== undefined; + // scroll to top + const isNewPage = params.from?.url.pathname !== params.to?.url.pathname; + const elemPage = document.querySelector("#page"); + if (isNewPage && elemPage !== null) { + elemPage.scrollTop = 0; + } }); initializeStores();