From 6e234393595b19c16ff874046441575fb5801359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=A0=91=E6=A0=91?= Date: Tue, 27 Jan 2026 23:28:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#159=20(=E5=B8=83=E5=B1=80):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=A1=B5=E9=9D=A2=E6=BB=9A=E5=8A=A8=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E5=BC=95=E7=94=A8=E5=88=B7=E6=96=B0=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在页面切换后,滚动控制相关的DOM元素引用未及时更新,导致滚动功能失效。添加refreshControlRefs函数在每次滚动检查前刷新引用,并确保页面加载完成后立即执行一次滚动检查。 --- src/layouts/Layout.astro | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index e0df74014..5caf02dfc 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -503,6 +503,7 @@ const setup = () => { if (heightExtend) { heightExtend.classList.remove('hidden') } + scrollFunction() }); window.swup.hooks.on('visit:end', (_visit: {to: {url: string}}) => { setTimeout(() => { @@ -529,7 +530,14 @@ let backToTopBtn = document.getElementById('back-to-top-btn'); let goToCommentsBtn = document.getElementById('go-to-comments-btn'); let toc = document.getElementById('toc-wrapper'); let navbar = document.getElementById('navbar-wrapper') +function refreshControlRefs() { + backToTopBtn = document.getElementById('back-to-top-btn'); + goToCommentsBtn = document.getElementById('go-to-comments-btn'); + toc = document.getElementById('toc-wrapper'); + navbar = document.getElementById('navbar-wrapper') +} function scrollFunction() { + refreshControlRefs() let bannerHeight = window.innerHeight * (BANNER_HEIGHT / 100) if (backToTopBtn) { @@ -576,6 +584,11 @@ function scrollFunction() { } } window.onscroll = scrollFunction +if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', scrollFunction) +} else { + scrollFunction() +} window.onresize = () => { // calculate the --banner-height-extend, which needs to be a multiple of 4 to avoid blurry text