From 613b3a2f6e37bd2b51f06f85cba0dc7b897f61e1 Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 7 Mar 2026 21:11:28 -0600 Subject: [PATCH] 's' --- src/pages/book/index.tsx | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/pages/book/index.tsx b/src/pages/book/index.tsx index bbaaace..75c1c94 100644 --- a/src/pages/book/index.tsx +++ b/src/pages/book/index.tsx @@ -16,9 +16,10 @@ function getPb() { const LazyChunk = React.memo(({ html, estimatedHeight, forceVisible }) => { const [visible, setVisible] = useState(forceVisible); const ref = useRef(null); + const show = forceVisible || visible; useEffect(() => { - if (forceVisible) { setVisible(true); return; } + if (forceVisible) return; if (visible) return; const el = ref.current; if (!el) return; @@ -35,7 +36,7 @@ const LazyChunk = React.memo(({ html, estimatedHeight, forceVisible }) => { return () => observer.disconnect(); }, [forceVisible, visible]); - if (visible) { + if (show) { return
; } return
; @@ -195,18 +196,29 @@ const Book = () => { }; }, [contentLoading]); - const handleJump = useCallback((text) => { + const handleJump = useCallback((index) => { setForceShowAll(true); - setTimeout(() => { - if (!contentRef.current) return; - const h1s = contentRef.current.querySelectorAll("h1"); - for (let h1 of h1s) { - if (h1.textContent.trim() === text.trim()) { - h1.scrollIntoView({ behavior: "smooth" }); - break; + setshow(false); + + const run = () => { + const root = contentRef.current; + if (!root) return; + const h1s = root.querySelectorAll("h1"); + const el = h1s[index]; + if (el) { + try { + el.scrollIntoView({ behavior: "smooth", block: "start" }); + } catch (_) { + const top = el.getBoundingClientRect().top + (window.pageYOffset || document.documentElement.scrollTop) - 60; + window.scrollTo({ top: Math.max(0, top), behavior: "smooth" }); } } - }, 200); + }; + + run(); + setTimeout(run, 100); + setTimeout(run, 300); + setTimeout(run, 600); }, []); const submitPayForm = (xorpayUrl, xorpayParams) => { @@ -284,7 +296,7 @@ const Book = () => { show={show} mask items={activeHeaders} - onItemClick={(index) => handleJump(activeHeaders[index])} + onItemClick={(index) => handleJump(index)} onClose={() => setshow(false)} />