From d0c0f3ab93162deeff088f2c6b2696ac4897e34c Mon Sep 17 00:00:00 2001 From: kvakazyambra Date: Fri, 4 Nov 2022 16:05:50 +0300 Subject: [PATCH 1/2] Fixed document scroll position when modal opened --- src/components/Nav/Header.tsx | 15 +++++++++++++++ src/styles/app.scss | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/Nav/Header.tsx b/src/components/Nav/Header.tsx index e9d6b598..8e94b426 100644 --- a/src/components/Nav/Header.tsx +++ b/src/components/Nav/Header.tsx @@ -49,9 +49,24 @@ export const Header = (props: Props) => { const toggleWarnings = () => setVisibleWarnings(!visibleWarnings()) const toggleFixed = () => setFixed((oldFixed) => !oldFixed) // effects + + let windowScrollTop = 0 + createEffect(() => { + const mainContent = document.querySelector('.main-content') + + if (fixed() || modal() !== null) { + windowScrollTop = window.scrollY + mainContent.style.marginTop = `-${windowScrollTop}px` + } + document.body.classList.toggle('fixed', fixed() || modal() !== null) document.body.classList.toggle(styles.fixed, fixed() && !modal()) + + if (!fixed() && !modal()) { + mainContent.style.marginTop = '' + window.scrollTo(0, windowScrollTop) + } }) // derived diff --git a/src/styles/app.scss b/src/styles/app.scss index 0e6e02e6..fff35a04 100644 --- a/src/styles/app.scss +++ b/src/styles/app.scss @@ -565,7 +565,6 @@ astro-island { min-height: 300px; padding-top: 100px; position: relative; - transition: all 1s ease; } .main-content--no-padding { From 2e53d894c4a98bd60aeb4658be67d54e563b579e Mon Sep 17 00:00:00 2001 From: kvakazyambra Date: Fri, 4 Nov 2022 16:58:42 +0300 Subject: [PATCH 2/2] Fixed linter error --- src/components/Nav/Header.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Nav/Header.tsx b/src/components/Nav/Header.tsx index 8e94b426..f87c6825 100644 --- a/src/components/Nav/Header.tsx +++ b/src/components/Nav/Header.tsx @@ -53,7 +53,7 @@ export const Header = (props: Props) => { let windowScrollTop = 0 createEffect(() => { - const mainContent = document.querySelector('.main-content') + const mainContent = document.querySelector('.main-content') as HTMLDivElement if (fixed() || modal() !== null) { windowScrollTop = window.scrollY