From 4f8d6a0a11a7b4ae960f768dab0d25e2b2e33f6f Mon Sep 17 00:00:00 2001 From: codytseng Date: Sun, 31 Aug 2025 12:05:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/PrimaryPageLayout/index.tsx | 30 +++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/layouts/PrimaryPageLayout/index.tsx b/src/layouts/PrimaryPageLayout/index.tsx index 6b9a9b2..bf34a44 100644 --- a/src/layouts/PrimaryPageLayout/index.tsx +++ b/src/layouts/PrimaryPageLayout/index.tsx @@ -45,20 +45,26 @@ const PrimaryPageLayout = forwardRef( ) useEffect(() => { - if (isSmallScreen) { - if (smallScreenScrollAreaRef.current?.checkVisibility()) { - window.scrollTo({ top: smallScreenLastScrollTopRef.current, behavior: 'instant' }) - } - const handleScroll = () => { - if (smallScreenScrollAreaRef.current?.checkVisibility()) { - smallScreenLastScrollTopRef.current = window.scrollY - } - } - window.addEventListener('scroll', handleScroll) - return () => { - window.removeEventListener('scroll', handleScroll) + if (!isSmallScreen) return + + const isVisible = () => { + return smallScreenScrollAreaRef.current?.checkVisibility + ? smallScreenScrollAreaRef.current?.checkVisibility() + : false + } + + if (isVisible()) { + window.scrollTo({ top: smallScreenLastScrollTopRef.current, behavior: 'instant' }) + } + const handleScroll = () => { + if (isVisible()) { + smallScreenLastScrollTopRef.current = window.scrollY } } + window.addEventListener('scroll', handleScroll) + return () => { + window.removeEventListener('scroll', handleScroll) + } }, [current, isSmallScreen, display]) if (isSmallScreen) {