-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: scroll 여부 파악하는 custom hook 제작 * feat: 아래로 스크롤 시 category 사라지도록 구현 * feat: top y scroll position 동적으로 받도록 수정 * design: section간 간격 수정 * chore: 변수 네이밍 좀 더 구체적으로
- Loading branch information
1 parent
dd09c80
commit 37391a4
Showing
6 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
const useScrollPosition = (topYScrollPosition: number = 20) => { | ||
const lastScrollPositionRef = useRef(0); | ||
const [isScrollingDown, setIsScrollingDown] = useState(true); | ||
const [isScrollTop, setIsScrollTop] = useState(true); | ||
|
||
useEffect(() => { | ||
const scrollHandler = () => { | ||
const currentScrollPosition = window.scrollY; | ||
|
||
setIsScrollTop(currentScrollPosition < topYScrollPosition); | ||
setIsScrollingDown(lastScrollPositionRef.current < currentScrollPosition); | ||
|
||
lastScrollPositionRef.current = currentScrollPosition; | ||
}; | ||
|
||
window.addEventListener('scroll', scrollHandler); | ||
|
||
return () => { | ||
window.removeEventListener('scroll', scrollHandler); | ||
}; | ||
}, [topYScrollPosition]); | ||
|
||
return { | ||
isScrollingDown, | ||
isScrollTop, | ||
}; | ||
}; | ||
|
||
export default useScrollPosition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters