Merge pull request 'Fixed the bug of being unable to use ctrl+scroll wheel to adjust zoom. Add full page scroll to Home' (#14) from FatttSnake into dev
Reviewed-on: FatttSnake/fatweb-ui#14
This commit was merged in pull request #14.
This commit is contained in:
@@ -45,7 +45,9 @@ const HideScrollbar = forwardRef<HideScrollbarElement, HideScrollbarProps>((prop
|
|||||||
|
|
||||||
const { isPreventScroll, ..._props } = props
|
const { isPreventScroll, ..._props } = props
|
||||||
const handleDefaultWheel = useCallback((event: WheelEvent) => {
|
const handleDefaultWheel = useCallback((event: WheelEvent) => {
|
||||||
|
if (!event.altKey && !event.ctrlKey) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleDefaultTouchmove = useCallback((event: TouchEvent) => {
|
const handleDefaultTouchmove = useCallback((event: TouchEvent) => {
|
||||||
@@ -200,7 +202,12 @@ const HideScrollbar = forwardRef<HideScrollbarElement, HideScrollbarProps>((prop
|
|||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('resize', windowResizeListener)
|
window.removeEventListener('resize', windowResizeListener)
|
||||||
}
|
}
|
||||||
}, [isPreventScroll])
|
}, [
|
||||||
|
handleDefaultClickMiddleMouseButton,
|
||||||
|
handleDefaultTouchmove,
|
||||||
|
handleDefaultWheel,
|
||||||
|
isPreventScroll
|
||||||
|
])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -13,8 +13,11 @@ const Home: React.FC = () => {
|
|||||||
} = useContext(MainFrameworkContext)
|
} = useContext(MainFrameworkContext)
|
||||||
const fitFullScreenRef = useRef<HTMLDivElement>(null)
|
const fitFullScreenRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
const scrollTimeout = useRef<number>()
|
||||||
|
|
||||||
const [slogan, setSlogan] = useState('')
|
const [slogan, setSlogan] = useState('')
|
||||||
const [sloganType, setSloganType] = useState(true)
|
const [sloganType, setSloganType] = useState(true)
|
||||||
|
const [currentContent, setCurrentContent] = useState(0)
|
||||||
|
|
||||||
const typeText = '/* 因为热爱 所以折腾 */'
|
const typeText = '/* 因为热爱 所以折腾 */'
|
||||||
if (sloganType) {
|
if (sloganType) {
|
||||||
@@ -42,30 +45,53 @@ const Home: React.FC = () => {
|
|||||||
})
|
})
|
||||||
}, [setNavbarHidden, setPreventScroll])
|
}, [setNavbarHidden, setPreventScroll])
|
||||||
|
|
||||||
const handleScrollToDown = () => {
|
const handleScrollToContent = (index: number) => {
|
||||||
hideScrollbarRef.current?.scrollY(fitFullScreenRef.current?.offsetHeight ?? 0)
|
return () => {
|
||||||
|
if (!index) {
|
||||||
|
setNavbarHidden(true)
|
||||||
|
hideScrollbarRef.current?.scrollY(0)
|
||||||
|
} else {
|
||||||
|
hideScrollbarRef.current?.scrollY(
|
||||||
|
(fitFullScreenRef.current?.offsetHeight ?? 0) * index
|
||||||
|
)
|
||||||
setNavbarHidden(false)
|
setNavbarHidden(false)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const handleScrollToTop = () => {
|
|
||||||
hideScrollbarRef.current?.scrollY(0)
|
|
||||||
setNavbarHidden(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleWheel = (event: React.WheelEvent) => {
|
const handleWheel = (event: React.WheelEvent) => {
|
||||||
|
if (event.altKey || event.ctrlKey) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (event.deltaY > 0) {
|
if (event.deltaY > 0) {
|
||||||
handleScrollToDown()
|
if (currentContent >= content.length) {
|
||||||
setNavbarHidden(false)
|
return
|
||||||
|
}
|
||||||
|
handleScrollToContent(currentContent + 1)()
|
||||||
|
clearTimeout(scrollTimeout.current ?? 0)
|
||||||
|
scrollTimeout.current = setTimeout(() => {
|
||||||
|
setCurrentContent(currentContent + 1)
|
||||||
|
console.log(`up ${currentContent + 1}`)
|
||||||
|
}, 500)
|
||||||
} else {
|
} else {
|
||||||
handleScrollToTop()
|
if (currentContent <= 0) {
|
||||||
setNavbarHidden(true)
|
return
|
||||||
|
}
|
||||||
|
handleScrollToContent(currentContent - 1)()
|
||||||
|
clearTimeout(scrollTimeout.current ?? 0)
|
||||||
|
scrollTimeout.current = setTimeout(() => {
|
||||||
|
setCurrentContent(currentContent - 1)
|
||||||
|
console.log(`down ${currentContent - 1}`)
|
||||||
|
}, 500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const content = [
|
||||||
<>
|
{
|
||||||
<div onWheel={handleWheel}>
|
backgroundColor: '#FBFBFB',
|
||||||
<FitFullScreen backgroundColor={'#FBFBFB'} ref={fitFullScreenRef}>
|
ref: fitFullScreenRef,
|
||||||
|
children: (
|
||||||
<FitCenter>
|
<FitCenter>
|
||||||
<div className={'center-box'}>
|
<div className={'center-box'}>
|
||||||
<div className={'big-logo'}>FatWeb</div>
|
<div className={'big-logo'}>FatWeb</div>
|
||||||
@@ -73,16 +99,25 @@ const Home: React.FC = () => {
|
|||||||
{slogan || <> </>}
|
{slogan || <> </>}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className={'scroll-down'} onClick={handleScrollToDown}>
|
<div className={'scroll-down'} onClick={handleScrollToContent(1)}>
|
||||||
<Icon
|
<Icon
|
||||||
component={IconFatwebDown}
|
component={IconFatwebDown}
|
||||||
style={{ fontSize: '1.8em', color: '#666' }}
|
style={{ fontSize: '1.8em', color: '#666' }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</FitCenter>
|
</FitCenter>
|
||||||
</FitFullScreen>
|
)
|
||||||
<FitFullScreen />
|
},
|
||||||
<FitFullScreen />
|
{ children: <FitCenter>2</FitCenter> },
|
||||||
|
{ children: <FitCenter>3</FitCenter> }
|
||||||
|
]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div onWheel={handleWheel}>
|
||||||
|
{content.map((element, index) => {
|
||||||
|
return <FitFullScreen key={index} {...element} />
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user