From 201f4c8e23fd18cf20eaa5b66980eb4175c070fb Mon Sep 17 00:00:00 2001 From: saicaca Date: Mon, 28 Oct 2024 19:06:28 +0800 Subject: [PATCH] feat: scrolling to the top don't hide the TOC when banner is disabled --- src/layouts/Layout.astro | 14 +++++++------- src/layouts/MainGridLayout.astro | 6 ++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index cd5b665..af46e2c 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -413,18 +413,18 @@ const setup = () => { } }); window.swup.hooks.on('visit:end', (visit: {to: {url: string}}) => { - // execute 1s later setTimeout(() => { const heightExtend = document.getElementById('page-height-extend') if (heightExtend) { heightExtend.classList.add('hidden') } - }, 200) - const toc = document.getElementById('toc-wrapper'); - if (toc) { - toc.classList.remove('toc-not-ready') - } + // Just make the transition looks better + const toc = document.getElementById('toc-wrapper'); + if (toc) { + toc.classList.remove('toc-not-ready') + } + }, 200) }); } if (window?.swup?.hooks) { @@ -447,7 +447,7 @@ function scrollFunction() { } } - if (toc) { + if (bannerEnabled && toc) { if (document.body.scrollTop > bannerHeight || document.documentElement.scrollTop > bannerHeight) { toc.classList.remove('toc-hide') } else { diff --git a/src/layouts/MainGridLayout.astro b/src/layouts/MainGridLayout.astro index 189a9a6..1021712 100644 --- a/src/layouts/MainGridLayout.astro +++ b/src/layouts/MainGridLayout.astro @@ -93,9 +93,11 @@ const mainPanelTop = siteConfig.banner.enable ? `calc(${BANNER_HEIGHT}vh - ${MAI
- {siteConfig.toc.enable &&
+ {siteConfig.toc.enable &&
-
+