@@ -155,55 +155,36 @@ export default class SCROLL_EFFECT_MODULE {
155155 // Scroll top cache
156156 this . state . NumScrolltop = window . pageYOffset ;
157157
158- // Store element state at PosList.
159- this . state . PosList . map ( ( el ) => {
158+ // 要素のactive状態を設定するユーティリティ関数
159+ let setActiveState = ( el , active ) => {
160+ if ( el . active !== active ) {
161+ el . changing = true ;
162+ el . active = active ;
163+ }
164+ } ;
160165
161- // When displayRatio and displayRatioReverse are the SAME .
162- if ( this . config . displayRatio === this . config . displayRatioReverse ) {
163- if ( this . state . NumScrolltop + ( this . NumWindowHeight * this . config . displayRatio ) > el . pos ) {
164- if ( ! el . active ) {
165- el . changing = true ;
166- el . active = true ;
167- }
166+ // Store element state at PosList .
167+ this . state . PosList . forEach ( el => {
168+ if ( this . config . displayRatio === this . config . displayRatioReverse ) {
169+ // displayRatioとdisplayRatioReverseが同じ場合の処理
170+ if ( this . state . NumScrolltop + ( this . NumWindowHeight * this . config . displayRatio ) > el . pos ) {
171+ // 画面内に要素が表示された場合
172+ setActiveState ( el , true ) ;
168173 } else {
169- // 「none active」Set of lists
170- if ( el . active ) {
171- el . changing = true ;
172- el . active = false ;
173- }
174+ // 画面外に要素が移動した場合
175+ setActiveState ( el , false ) ;
174176 }
175- }
176-
177- // When displayRatio and displayRatioReverse are the DIFFERENT.
178- if ( this . config . displayRatio !== this . config . displayRatioReverse ) {
179- if ( this . state . NumScrolltop + ( this . NumWindowHeight * this . config . displayRatio ) > el . pos ) {
180- // 「active」Set of lists
181- if ( ! el . active ) {
182- el . changing = true ;
183- el . active = true ;
184- }
177+ } else {
178+ // displayRatioとdisplayRatioReverseが異なる場合の処理
179+ if ( this . state . NumScrolltop + ( this . NumWindowHeight * this . config . displayRatio ) > el . pos ) {
180+ // displayRatioで設定された閾値を満たした場合
181+ setActiveState ( el , true ) ;
182+ } else if ( this . state . NumScrolltop + ( this . NumWindowHeight * this . config . displayRatioReverse ) > el . pos ) {
183+ // displayRatioReverseで設定された閾値を満たした場合
184+ setActiveState ( el , true ) ;
185185 } else {
186- if ( this . state . NumScrolltop + ( this . NumWindowHeight * this . config . displayRatioReverse ) > el . pos ) {
187- if ( el . active ) {
188- // 「active」Set of lists
189- if ( ! el . active ) {
190- el . changing = true ;
191- el . active = true ;
192- }
193- } else {
194- // 「none active」Set of lists
195- if ( el . active ) {
196- el . changing = true ;
197- el . active = false ;
198- }
199- }
200- } else {
201- // 「none active」Set of lists
202- if ( el . active ) {
203- el . changing = true ;
204- el . active = false ;
205- }
206- }
186+ // どの閾値も満たさない場合
187+ setActiveState ( el , false ) ;
207188 }
208189 }
209190 } ) ;
0 commit comments