@@ -114,7 +114,7 @@ class ScrollParallax extends React.Component {
114
114
}
115
115
116
116
resizeEventListener = ( ) => {
117
- if ( this . onCompleteBool && ! this . props . always ) {
117
+ if ( this . defaultData [ this . defaultData . length - 1 ] && this . defaultData [ this . defaultData . length - 1 ] . onCompleteBool && ! this . props . always ) {
118
118
return ;
119
119
}
120
120
this . scrollTop = currentScrollTop ( ) ;
@@ -140,51 +140,52 @@ class ScrollParallax extends React.Component {
140
140
const offsetTop = dom . getBoundingClientRect ( ) . top + scrollTop - targetTop ;
141
141
const elementShowHeight = scrollTop - offsetTop + this . clientHeight ;
142
142
const currentShow = this . scrollTop - offsetTop + this . clientHeight ;
143
- this . defaultData . forEach ( item => {
143
+ this . defaultData . forEach ( ( item , i ) => {
144
+ const duration = this . defaultData . map ( ( c , ii ) => ii < i && c . delay + c . duration || 0 ) . reduce ( ( a , b ) => a + b ) ;
144
145
let noUpdate ;
145
- if ( elementShowHeight <= item . delay ) {
146
- if ( ! this . onCompleteBackBool && this . onStartBool ) {
147
- this . onCompleteBackBool = true ;
146
+ if ( elementShowHeight <= item . delay + duration ) {
147
+ if ( ! item . onCompleteBackBool && item . onStartBool ) {
148
+ item . onCompleteBackBool = true ;
148
149
noUpdate = true ;
149
150
item . onCompleteBack ( ) ;
150
151
}
151
152
} else {
152
- this . onCompleteBackBool = false ;
153
+ item . onCompleteBackBool = false ;
153
154
}
154
- if ( elementShowHeight >= item . delay ) {
155
- if ( ! this . onStartBool ) {
156
- this . onStartBool = true ;
155
+ if ( elementShowHeight >= item . delay + duration ) {
156
+ if ( ! item . onStartBool ) {
157
+ item . onStartBool = true ;
157
158
noUpdate = true ;
158
159
item . onStart ( ) ;
159
160
}
160
161
} else {
161
- this . onStartBool = false ;
162
+ item . onStartBool = false ;
162
163
}
163
164
164
- if ( elementShowHeight <= item . delay + item . duration ) {
165
- if ( ! this . onStartBackBool && this . onCompleteBool ) {
166
- this . onStartBackBool = true ;
165
+ if ( elementShowHeight <= item . delay + item . duration + duration ) {
166
+ if ( ! item . onStartBackBool && item . onCompleteBool ) {
167
+ item . onStartBackBool = true ;
167
168
noUpdate = true ;
168
169
item . onStartBack ( ) ;
169
170
}
170
171
} else {
171
- this . onStartBackBool = false ;
172
+ item . onStartBackBool = false ;
172
173
}
173
174
174
- if ( elementShowHeight >= item . delay + item . duration ) {
175
- if ( ! this . onCompleteBool ) {
176
- this . onCompleteBool = true ;
175
+ if ( elementShowHeight >= item . delay + item . duration + duration ) {
176
+ if ( ! item . onCompleteBool ) {
177
+ item . onCompleteBool = true ;
177
178
noUpdate = true ;
178
179
item . onComplete ( ) ;
179
180
}
180
181
} else {
181
- this . onCompleteBool = false ;
182
+ item . onCompleteBool = false ;
182
183
}
183
- if ( elementShowHeight >= item . delay &&
184
- elementShowHeight <= item . delay + item . duration &&
184
+ if ( elementShowHeight >= item . delay + duration &&
185
+ elementShowHeight <= item . delay + item . duration + duration &&
185
186
! noUpdate
186
187
) {
187
- item . onUpdate ( elementShowHeight / ( item . delay + item . duration ) ) ;
188
+ item . onUpdate ( elementShowHeight / ( item . delay + item . duration + duration ) ) ;
188
189
}
189
190
} ) ;
190
191
ticker . clear ( this . tickerId ) ;
@@ -205,7 +206,7 @@ class ScrollParallax extends React.Component {
205
206
206
207
this . scrollTop = scrollTop ;
207
208
// 如果不一直靠滚动来执行动画,always=false而且动画全执行完了,,删除scrollEvent;
208
- if ( this . onCompleteBool && this . eventType && ! this . props . always ) {
209
+ if ( this . defaultData [ this . defaultData . length - 1 ] . onCompleteBool && this . eventType && ! this . props . always ) {
209
210
EventListener . removeEventListener ( this . eventType , this . scrollEventListener , this . target ) ;
210
211
}
211
212
}
0 commit comments