diff --git a/src/components/HideScrollbar.tsx b/src/components/HideScrollbar.tsx index 76a3714..8e0e0b7 100644 --- a/src/components/HideScrollbar.tsx +++ b/src/components/HideScrollbar.tsx @@ -45,7 +45,9 @@ const HideScrollbar = forwardRef((prop const { isPreventScroll, ..._props } = props const handleDefaultWheel = useCallback((event: WheelEvent) => { - event.preventDefault() + if (!event.altKey && !event.ctrlKey) { + event.preventDefault() + } }, []) const handleDefaultTouchmove = useCallback((event: TouchEvent) => { @@ -200,7 +202,12 @@ const HideScrollbar = forwardRef((prop return () => { window.removeEventListener('resize', windowResizeListener) } - }, [isPreventScroll]) + }, [ + handleDefaultClickMiddleMouseButton, + handleDefaultTouchmove, + handleDefaultWheel, + isPreventScroll + ]) return ( <> diff --git a/src/components/Home.tsx b/src/components/Home.tsx index afde976..51af362 100644 --- a/src/components/Home.tsx +++ b/src/components/Home.tsx @@ -13,8 +13,11 @@ const Home: React.FC = () => { } = useContext(MainFrameworkContext) const fitFullScreenRef = useRef(null) + const scrollTimeout = useRef() + const [slogan, setSlogan] = useState('') const [sloganType, setSloganType] = useState(true) + const [currentContent, setCurrentContent] = useState(0) const typeText = '/* 因为热爱 所以折腾 */' if (sloganType) { @@ -42,47 +45,79 @@ const Home: React.FC = () => { }) }, [setNavbarHidden, setPreventScroll]) - const handleScrollToDown = () => { - hideScrollbarRef.current?.scrollY(fitFullScreenRef.current?.offsetHeight ?? 0) - setNavbarHidden(false) - } - - const handleScrollToTop = () => { - hideScrollbarRef.current?.scrollY(0) - setNavbarHidden(true) + const handleScrollToContent = (index: number) => { + return () => { + if (!index) { + setNavbarHidden(true) + hideScrollbarRef.current?.scrollY(0) + } else { + hideScrollbarRef.current?.scrollY( + (fitFullScreenRef.current?.offsetHeight ?? 0) * index + ) + setNavbarHidden(false) + } + } } const handleWheel = (event: React.WheelEvent) => { + if (event.altKey || event.ctrlKey) { + return + } + if (event.deltaY > 0) { - handleScrollToDown() - setNavbarHidden(false) + if (currentContent >= content.length) { + return + } + handleScrollToContent(currentContent + 1)() + clearTimeout(scrollTimeout.current ?? 0) + scrollTimeout.current = setTimeout(() => { + setCurrentContent(currentContent + 1) + console.log(`up ${currentContent + 1}`) + }, 500) } else { - handleScrollToTop() - setNavbarHidden(true) + if (currentContent <= 0) { + return + } + handleScrollToContent(currentContent - 1)() + clearTimeout(scrollTimeout.current ?? 0) + scrollTimeout.current = setTimeout(() => { + setCurrentContent(currentContent - 1) + console.log(`down ${currentContent - 1}`) + }, 500) } } + const content = [ + { + backgroundColor: '#FBFBFB', + ref: fitFullScreenRef, + children: ( + +
+
FatWeb
+ + {slogan || <> } + +
+
+ +
+
+ ) + }, + { children: 2 }, + { children: 3 } + ] + return ( <>
- - -
-
FatWeb
- - {slogan || <> } - -
-
- -
-
-
- - + {content.map((element, index) => { + return + })}
)