From e09edd45d7f5a746d661cd7b01916758443637ab Mon Sep 17 00:00:00 2001 From: ShenHongxuan <3012693863@qq.com> Date: Sun, 16 Aug 2026 20:24:10 +0800 Subject: [PATCH] Fix active section tracking --- demo-site/src/App.jsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/demo-site/src/App.jsx b/demo-site/src/App.jsx index 48033c8..3b468f6 100644 --- a/demo-site/src/App.jsx +++ b/demo-site/src/App.jsx @@ -199,9 +199,10 @@ export default function App() { const [activeSection, setActiveSection] = useState("overview"); useEffect(() => { const sections = NAV_ITEMS.map(([id]) => document.getElementById(id)).filter(Boolean); - const observer = new IntersectionObserver((entries) => { const visible = entries.filter((entry) => entry.isIntersecting).sort((a, b) => b.intersectionRatio - a.intersectionRatio)[0]; if (visible) setActiveSection(visible.target.id); }, { rootMargin: "-15% 0px -65%", threshold: [0, 0.2, 0.6] }); - sections.forEach((section) => observer.observe(section)); - return () => observer.disconnect(); + const syncActiveSection = () => { const marker = window.innerHeight * .28; const current = sections.filter((section) => section.getBoundingClientRect().top <= marker).at(-1) ?? sections[0]; setActiveSection(current.id); }; + syncActiveSection(); + window.addEventListener("scroll", syncActiveSection, { passive: true }); + return () => window.removeEventListener("scroll", syncActiveSection); }, []); return
跳到主要内容
; }