Browse Source

fix: 🐛

imwald
codytseng 7 months ago
parent
commit
4f8d6a0a11
  1. 30
      src/layouts/PrimaryPageLayout/index.tsx

30
src/layouts/PrimaryPageLayout/index.tsx

@ -45,20 +45,26 @@ const PrimaryPageLayout = forwardRef( @@ -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) {

Loading…
Cancel
Save