From 44fb628737cc858af24442e7b0dd6148b39304c8 Mon Sep 17 00:00:00 2001 From: saicaca Date: Mon, 16 Sep 2024 13:25:18 +0800 Subject: [PATCH] fix: fix navbar disappearing after link click (#182) --- src/layouts/Layout.astro | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 6692295b0..da6168039 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -234,6 +234,8 @@ function disableAnimation() { } */ +const bannerEnabled = !!document.getElementById('banner-wrapper') + function setClickOutsideToClose(panel: string, ignores: string[]) { document.addEventListener("click", event => { let panelDom = document.getElementById(panel); @@ -325,6 +327,9 @@ const setup = () => { document.documentElement.style.setProperty('--content-delay', '0ms') // prevent elements from overlapping the navbar + if (!bannerEnabled) { + return + } let threshold = window.innerHeight * 0.30 - 72 - 16 let navbar = document.getElementById('navbar-wrapper') if (!navbar || !document.body.classList.contains('lg:is-home')) { @@ -372,7 +377,6 @@ if (window?.swup?.hooks) { } let backToTopBtn = document.getElementById('back-to-top-btn'); -const bannerEnable = !!document.getElementById('banner-wrapper') let navbar = document.getElementById('navbar-wrapper') function scrollFunction() { if (backToTopBtn) { @@ -383,7 +387,7 @@ function scrollFunction() { } } - if (!bannerEnable) return + if (!bannerEnabled) return if (navbar) { let threshold = window.innerHeight * 0.30 - 72 - 16 if (document.body.classList.contains('lg:is-home') && window.innerWidth >= 1024) {