@@ -51,6 +51,12 @@ function FullpageSection({
5151 ) ;
5252 const [ scrollDelay , setScrollDelay ] = useState < boolean > ( false ) ;
5353 const { hashValue } = useHash ( ) ;
54+ const deltaWeightTimer = useRef < number > ( 0 ) ;
55+ const [ deltaWeight , setDeltaWeight ] = useState < number > ( 0 ) ; // wheel 가중치
56+ const [ lastDeltaWeight , setLastDeltaWeight ] = useState < number > ( 0 ) ;
57+ // wheel 속도가 마지막 wheel 속도보다 빠르면 true 또는 wheel이벤트가 300ms 이상 없으면 true
58+ const wheelTokenTimer = useRef < NodeJS . Timeout | null > ( null ) ;
59+ const wheelToken = useRef < boolean > ( true ) ;
5460
5561 useEffect ( ( ) => {
5662 if ( hashValue ) {
@@ -78,13 +84,8 @@ function FullpageSection({
7884 } , [ scrollDelay ] ) ;
7985
8086 const moveToSection = ( newIndex : number ) => {
81- if (
82- setIsAnimating === undefined ||
83- setActiveIndex === undefined ||
84- ! allowScroll
85- )
86- return ;
87- if ( isAnimating || scrollDelay ) return ;
87+ if ( setIsAnimating === undefined || setActiveIndex === undefined ) return ; // 타입 에러 회피용
88+ if ( ! allowScroll || isAnimating || scrollDelay ) return ;
8889 setIsAnimating ( true ) ;
8990 setActiveIndex ( newIndex ) ;
9091 } ;
@@ -112,6 +113,23 @@ function FullpageSection({
112113 } ;
113114
114115 const handelWheel = ( e : React . WheelEvent < HTMLDivElement > ) => {
116+ const t = new Date ( ) . getTime ( ) ;
117+ if ( t - deltaWeightTimer . current < 300 ) {
118+ const computed = deltaWeight + Math . abs ( e . deltaY ) ;
119+ if ( computed > lastDeltaWeight ) {
120+ // wheel의 속도가 lastDeltaWeight보다 높으면 token 초기화
121+ wheelToken . current = true ;
122+ }
123+ setDeltaWeight ( computed ) ;
124+ } else {
125+ setLastDeltaWeight ( deltaWeight ) ;
126+ deltaWeightTimer . current = t ;
127+ setDeltaWeight ( 0 ) ;
128+ }
129+
130+ // token이 false라면 스크립트 중지
131+ if ( ! wheelToken . current ) return ;
132+
115133 if ( e . deltaY > 0 ) {
116134 moveToNextSection ( ) ;
117135 }
@@ -120,6 +138,19 @@ function FullpageSection({
120138 }
121139 } ;
122140
141+ useEffect ( ( ) => {
142+ wheelToken . current = false ;
143+ if ( wheelTokenTimer . current !== null ) {
144+ clearTimeout ( wheelTokenTimer . current ) ;
145+ }
146+ wheelTokenTimer . current = setTimeout ( ( ) => {
147+ // wheel이벤트가 300ms동안 발생하지 않으면 token 초기화
148+ wheelToken . current = true ;
149+ setDeltaWeight ( 0 ) ;
150+ } , 300 ) ;
151+ // eslint-disable-next-line react-hooks/exhaustive-deps
152+ } , [ deltaWeight ] ) ;
153+
123154 const handleSwipeEnd = ( direction : SwipeDirection ) => {
124155 if ( direction === 'UP' ) {
125156 moveToNextSection ( ) ;
0 commit comments