@@ -51,6 +51,12 @@ function FullpageSection({
51
51
) ;
52
52
const [ scrollDelay , setScrollDelay ] = useState < boolean > ( false ) ;
53
53
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 ) ;
54
60
55
61
useEffect ( ( ) => {
56
62
if ( hashValue ) {
@@ -78,13 +84,8 @@ function FullpageSection({
78
84
} , [ scrollDelay ] ) ;
79
85
80
86
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 ;
88
89
setIsAnimating ( true ) ;
89
90
setActiveIndex ( newIndex ) ;
90
91
} ;
@@ -112,6 +113,23 @@ function FullpageSection({
112
113
} ;
113
114
114
115
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
+
115
133
if ( e . deltaY > 0 ) {
116
134
moveToNextSection ( ) ;
117
135
}
@@ -120,6 +138,19 @@ function FullpageSection({
120
138
}
121
139
} ;
122
140
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
+
123
154
const handleSwipeEnd = ( direction : SwipeDirection ) => {
124
155
if ( direction === 'UP' ) {
125
156
moveToNextSection ( ) ;
0 commit comments