Skip to content

Commit 1f64aff

Browse files
committed
fix timeline duration is 0 no trigger onStart in queue-anim
1 parent bdab573 commit 1f64aff

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

examples/easingPath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const anim = [
1919
{
2020
repeatDelay: 1000,
2121
duration: 1000,
22-
y: -30,
22+
y: 0,
2323
appearTo: 0,
2424
repeat: -1,
2525
yoyo: true,

src/Tween.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ p.render = function () {
291291
}
292292
if (!this.register || i && !initTime) {
293293
this.register = true;
294-
if (progressTime === 0 && item.duration) {
294+
if (progressTime === 0 && item.duration && item.delay) {
295295
return;
296296
}
297297
}
@@ -306,33 +306,40 @@ p.render = function () {
306306
moment: this.progressTime,
307307
...e,
308308
};
309-
if (progressTime >= (item.delay && reverse ? -this.perFrame + this.accuracy : 0) &&
309+
const maxPer = this.perFrame - this.accuracy;
310+
const startTime = item.delay && reverse ? -maxPer : 0;
311+
if (progressTime >= startTime &&
310312
!(progressTime > duration && item.mode === 'onComplete') &&
311313
this.start[i]) {
312314
const updateAnim = this.updateAnim === 'update';
313-
progressTime = (progressTime < this.perFrame - this.accuracy) && !reverse
315+
progressTime = (progressTime < maxPer) && !reverse
314316
&& item.duration >= this.perFrame ? 0 : progressTime;
315317
if (((progressTime >= duration - this.accuracy && !reverse) || (reverse && progressTime <= 0))
316318
&& repeatNum >= item.repeat) {
319+
if (item.mode === 'onComplete') {
320+
return;
321+
}
317322
// onReveresComplete 和 onComplete 统一用 onComplete;
318323
ratio = item.ease(reverse ? 0 : 1, startData, endData, 1);
319324
this.setRatio(ratio, item, i, item.currentRepeat !== repeatNum);
320325
if (!item.reset && !updateAnim) {
321326
// duration 为 0 时的一个回调;
322-
if (!duration) {
323-
item.onStart(e);
324-
cb.mode = 'onStart';
325-
this.onChange(cb);
327+
if (duration < maxPer) {
328+
if (!duration) {
329+
item.onStart(e);
330+
cb.mode = 'onStart';
331+
this.onChange(cb);
332+
}
326333
item.onUpdate({ ratio, ...e });
327334
cb.mode = 'onUpdate';
328-
this.onChange(cb)
335+
this.onChange(cb);
329336
}
330337
item.onComplete(e);
331-
} else if (progressTime >= duration + this.perFrame - this.accuracy) {
338+
} else if (progressTime >= duration + maxPer) {
332339
return;
333340
}
334341
item.mode = 'onComplete';
335-
} else if (duration) {
342+
} else if (duration > maxPer) {
336343
let currentProgress = progressTime < 0 ? 0 : progressTime;
337344
currentProgress = currentProgress > duration ? duration : currentProgress;
338345
ratio = item.ease(currentProgress, startData, endData, duration);
@@ -342,7 +349,8 @@ p.render = function () {
342349
item.mode = 'onRepeat';
343350
item.currentRepeat = repeatNum;
344351
item.onRepeat({ ...e, repeatNum });
345-
} else if ((typeof item.perTime !== 'number' || progressTime === 0 ||
352+
} else if ((typeof item.perTime !== 'number' ||
353+
progressTime >= startTime && progressTime <= maxPer ||
346354
(reverse && (item.perTime >= this.reverseStartTime - initTime)))
347355
&& item.mode !== 'onStart') {
348356
// onReveresStart 和 onStart 统一用 onStart;

src/TweenOne.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class TweenOne extends Component {
4242
constructor(props) {
4343
super(props);
4444
this.rafID = -1;
45-
this.setDefalut(props);
4645
this.paused = props.paused;
4746
this.reverse = props.reverse;
4847
this.updateAnim = false;
@@ -71,7 +70,6 @@ class TweenOne extends Component {
7170
if (nextProps.resetStyle && this.tween) {
7271
this.tween.resetDefaultStyle();
7372
}
74-
this.setDefalut(nextProps);
7573
this.updateAnim = true;
7674
}
7775

@@ -88,7 +86,7 @@ class TweenOne extends Component {
8886
this.play();
8987
}
9088
} else {
91-
this.setDefalut(nextProps);
89+
9290
this.updateAnim = true;
9391
}
9492
}
@@ -196,6 +194,7 @@ class TweenOne extends Component {
196194
this.updateAnim = false;
197195
const props = this.props;
198196
if (props.animation && Object.keys(props.animation).length) {
197+
this.setDefalut(props);
199198
this.tween = new Tween(this.dom, dataToArray(props.animation),
200199
{ attr: props.attr });
201200
this.tween.reverse = this.reverse;
@@ -252,8 +251,9 @@ class TweenOne extends Component {
252251
timelineMode: '',
253252
};
254253
if (
255-
(!moment && !this.reverse) ||
256-
(this.reverse && this.moment === this.startMoment)
254+
(this.moment === this.startMoment &&
255+
(!this.reverse && !e.index && e.mode === 'onStart') ||
256+
this.reverse)
257257
) {
258258
cb.timelineMode = 'onTimelineStart';
259259
} else if (

src/ticker.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ const ticker = new Ticker;
4141
p.tick = function (a) {
4242
ticker.elapsed = getTime() - ticker.lastUpdate;
4343
ticker.lastUpdate += ticker.elapsed;
44+
if (!ticker.frame) {
45+
ticker.frame++;
46+
} else {
47+
ticker.frame += Math.round(ticker.elapsed / ticker.perFrame);
48+
}
4449
ticker.tickFnArray.forEach(func => func(a));
4550
// 如果 object 里没对象了,自动杀掉;
4651
if (!ticker.tickFnArray.length) {
4752
ticker.sleep();
4853
return;
4954
}
50-
if (!ticker.frame) {
51-
ticker.frame++;
52-
} else {
53-
ticker.frame += Math.round(ticker.elapsed / ticker.perFrame);
54-
}
5555
ticker.id = requestAnimationFrame(ticker.tick);
5656
};
5757
let timeoutIdNumber = 0;

src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export function startConvertToEndUnit(
163163
}
164164
let horiz = /(?:Left|Right|Width|X)/i.test(style) || isOriginWidth;
165165
horiz = style === 'padding' || style === 'marign' ? true : horiz;
166-
let t = style.indexOf('border') !== -1 || style.indexOf('translate') !== -1 ?
166+
let t = style.indexOf('border') !== -1 || style.indexOf('translate') !== -1 || style === 'transformOrigin' ?
167167
target : target.parentNode || document.body;
168168
t = fixed ? document.body : t;
169169
let pix;

0 commit comments

Comments
 (0)