Skip to content

Commit 6f147c2

Browse files
committed
1 parent ad5dcda commit 6f147c2

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-scroll-anim",
3-
"version": "2.6.1",
3+
"version": "2.6.2",
44
"description": "scroll-anim anim component for react",
55
"keywords": [
66
"react",

src/ScrollParallax.jsx

+23-22
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ScrollParallax extends React.Component {
114114
}
115115

116116
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) {
118118
return;
119119
}
120120
this.scrollTop = currentScrollTop();
@@ -140,51 +140,52 @@ class ScrollParallax extends React.Component {
140140
const offsetTop = dom.getBoundingClientRect().top + scrollTop - targetTop;
141141
const elementShowHeight = scrollTop - offsetTop + this.clientHeight;
142142
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);
144145
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;
148149
noUpdate = true;
149150
item.onCompleteBack();
150151
}
151152
} else {
152-
this.onCompleteBackBool = false;
153+
item.onCompleteBackBool = false;
153154
}
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;
157158
noUpdate = true;
158159
item.onStart();
159160
}
160161
} else {
161-
this.onStartBool = false;
162+
item.onStartBool = false;
162163
}
163164

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;
167168
noUpdate = true;
168169
item.onStartBack();
169170
}
170171
} else {
171-
this.onStartBackBool = false;
172+
item.onStartBackBool = false;
172173
}
173174

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;
177178
noUpdate = true;
178179
item.onComplete();
179180
}
180181
} else {
181-
this.onCompleteBool = false;
182+
item.onCompleteBool = false;
182183
}
183-
if (elementShowHeight >= item.delay &&
184-
elementShowHeight <= item.delay + item.duration &&
184+
if (elementShowHeight >= item.delay + duration &&
185+
elementShowHeight <= item.delay + item.duration + duration &&
185186
!noUpdate
186187
) {
187-
item.onUpdate(elementShowHeight / (item.delay + item.duration));
188+
item.onUpdate(elementShowHeight / (item.delay + item.duration + duration));
188189
}
189190
});
190191
ticker.clear(this.tickerId);
@@ -205,7 +206,7 @@ class ScrollParallax extends React.Component {
205206

206207
this.scrollTop = scrollTop;
207208
// 如果不一直靠滚动来执行动画,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) {
209210
EventListener.removeEventListener(this.eventType, this.scrollEventListener, this.target);
210211
}
211212
}

0 commit comments

Comments
 (0)