@@ -89,8 +89,13 @@ export class SCROLL_EFFECT_MODULE {
8989 this . State . NumScrolltop = window . pageYOffset ;
9090 let _elem = DOM . selectDom ( this . $elemItem ) ;
9191 if ( _elem ) {
92- _elem . map ( ( el ) => {
93- this . State . PosList . push ( el . getBoundingClientRect ( ) . top + this . State . NumScrolltop ) ;
92+ _elem . map ( ( el , i ) => {
93+ let obj = {
94+ index : i ,
95+ pos : el . getBoundingClientRect ( ) . top + this . State . NumScrolltop ,
96+ count : 0
97+ } ;
98+ this . State . PosList . push ( obj ) ;
9499 } ) ;
95100 }
96101 }
@@ -124,12 +129,19 @@ export class SCROLL_EFFECT_MODULE {
124129
125130 // Store element state at PosList.
126131 this . State . PosList . map ( ( el , i ) => {
127- if ( this . State . NumScrolltop + ( this . NumWindowHeight * this . Config . displayRatio ) > el ) {
132+ if ( this . State . NumScrolltop + ( this . NumWindowHeight * this . Config . displayRatio ) > el . pos ) {
133+
134+ // First count up.
135+ if ( method === 'load' ) {
136+ el . count ++ ;
137+ }
138+
128139 // 「active」Set of lists
129- this . State . PosListFix . push ( i ) ;
140+ this . State . PosListFix . push ( el ) ;
130141 } else {
142+
131143 // 「none active」Set of lists
132- this . State . PosListNoneFix . push ( i ) ;
144+ this . State . PosListNoneFix . push ( el ) ;
133145 }
134146 } ) ;
135147
@@ -222,27 +234,31 @@ export class SCROLL_EFFECT_MODULE {
222234 ActionChange ( ) {
223235
224236 this . State . PosListFix . map ( ( el ) => {
225- if ( ! DOM . hasClass ( this . $elemItem [ el ] , this . Config . addClassNameActive ) ) {
226- if ( this . Config . addClassNameActive ) DOM . addClass ( this . $elemItem [ el ] , this . Config . addClassNameActive ) ;
237+ if ( ! DOM . hasClass ( this . $elemItem [ el . index ] , this . Config . addClassNameActive ) ) {
238+ el . count ++ ;
239+ if ( this . Config . addClassNameActive ) DOM . addClass ( this . $elemItem [ el . index ] , this . Config . addClassNameActive ) ;
227240
228241 // Callback function.
229- if ( this . Config . on . In && typeof ( this . Config . on . In ) === 'function' ) this . Config . on . In ( this . $elemItem [ el ] , el , this . State . NumScrolltop ) ;
242+ if ( this . Config . on . In && typeof ( this . Config . on . In ) === 'function' ) this . Config . on . In ( this . $elemItem [ el . index ] , el . index , el , this . State . NumScrolltop ) ;
230243 }
231244 } ) ;
232245
233246 if ( this . Config . displayReverse ) {
234247 this . State . PosListNoneFix . map ( ( el ) => {
235- if ( DOM . hasClass ( this . $elemItem [ el ] , this . Config . addClassNameActive ) ) {
236- DOM . removeClass ( this . $elemItem [ el ] , this . Config . addClassNameActive ) ;
248+ if ( DOM . hasClass ( this . $elemItem [ el . index ] , this . Config . addClassNameActive ) ) {
249+ DOM . removeClass ( this . $elemItem [ el . index ] , this . Config . addClassNameActive ) ;
237250
238251 // Callback function.
239- if ( this . Config . on . Out && typeof ( this . Config . on . Out ) === 'function' ) this . Config . on . Out ( this . $elemItem [ el ] , el , this . State . NumScrolltop ) ;
252+ if ( this . Config . on . Out && typeof ( this . Config . on . Out ) === 'function' ) this . Config . on . Out ( this . $elemItem [ el . index ] , el . index , el , this . State . NumScrolltop ) ;
240253 }
241254 } ) ;
242255 }
243256
244257 // Callback function.
245- if ( this . Config . on . Change && typeof ( this . Config . on . Change ) === 'function' ) this . Config . on . Change ( this . $elemItem [ this . State . PosListFix . length - 1 ] , this . State . PosListFix . length , this . State . NumScrolltop ) ;
258+ if ( this . Config . on . Change && typeof ( this . Config . on . Change ) === 'function' ) {
259+ let _pf = this . State . PosListFix ;
260+ this . Config . on . Change ( this . $elemItem [ _pf . length - 1 ] , _pf . length , _pf [ _pf . length - 1 ] , this . State . NumScrolltop ) ;
261+ }
246262
247263 }
248264
0 commit comments