Optimize scroll in Home

This commit is contained in:
2023-09-11 23:22:51 +08:00
parent 28ff5c5534
commit f4425db537
2 changed files with 10 additions and 29 deletions

View File

@@ -12,11 +12,9 @@ const Home: React.FC = () => {
preventScrollState: { setPreventScroll }
} = useContext(MainFrameworkContext)
const fitFullScreenRef = useRef<HTMLDivElement>(null)
const pathname = useLocation().pathname
const [slogan, setSlogan] = useState('')
const [sloganType, setSloganType] = useState(true)
const [showSlogan, setShowSlogan] = useState(true)
const typeText = '/* 因为热爱 所以折腾 */'
if (sloganType) {
@@ -40,44 +38,27 @@ const Home: React.FC = () => {
useEffect(() => {
setTimeout(() => {
setNavbarHidden(true)
setPreventScroll(true)
})
}, [setNavbarHidden])
useEffect(() => {
setNavbarHidden(true)
}, [pathname, setNavbarHidden])
}, [setNavbarHidden, setPreventScroll])
const handleScrollToDown = () => {
hideScrollbarRef.current?.scrollY(fitFullScreenRef.current?.offsetHeight ?? 0)
setNavbarHidden(false)
}
const handleScrollToTop = () => {
hideScrollbarRef.current?.scrollY(0)
setNavbarHidden(true)
}
const handleWheel = (event: React.WheelEvent) => {
if (showSlogan) {
if (event.deltaY > 0) {
handleScrollToDown()
setPreventScroll(false)
setShowSlogan(false)
setNavbarHidden(false)
}
if (event.deltaY > 0) {
handleScrollToDown()
setNavbarHidden(false)
} else {
console.log(
hideScrollbarRef.current?.getY() + ' ' + fitFullScreenRef.current?.offsetHeight
)
if (
hideScrollbarRef.current &&
fitFullScreenRef.current &&
hideScrollbarRef.current.getY() < fitFullScreenRef.current.offsetHeight
) {
console.log('上翻')
setPreventScroll(true)
setShowSlogan(true)
setNavbarHidden(true)
handleScrollToTop()
}
handleScrollToTop()
setNavbarHidden(true)
}
}

View File

@@ -35,7 +35,7 @@ const MainFramework: React.FC = () => {
const hideScrollbarRef = useRef<HideScrollbarElement>(null)
const [navbarHidden, setNavbarHidden] = useState(true)
const [preventScroll, setPreventScroll] = useState(true)
const [preventScroll, setPreventScroll] = useState(false)
useEffect(() => {
setNavbarHidden(false)