Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Fix callbacks regression on timeline

Julian Garnier8704a83ae7cb
diff --git a/documentation/examples/anime-timeline.html b/documentation/examples/anime-timeline.html
index 538e6e1f..f23e9274 100644
--- a/documentation/examples/anime-timeline.html
+++ b/documentation/examples/anime-timeline.html
@@ -110,7 +110,7 @@
complete: function(anim) {
console.log('tl complete');
},
- autoplay: false
+ autoplay: true
});
document.querySelector('.controls .play').onclick = tl.play;
@@ -160,16 +160,18 @@
complete: function() { console.log('animation 5 completed')}
});
- controlsProgressEl.addEventListener('input', function() {
- tl.seek(tl.duration * (controlsProgressEl.value / 100));
- });
+ // controlsProgressEl.addEventListener('input', function() {
+ // tl.seek(tl.duration * (controlsProgressEl.value / 100));
+ // });
+
+ // for (var i = 0; i < els.length; i++) {
+ // els[i].addEventListener('mouseenter', function() {
+ // anime.remove(this);
+ // this.style.backgroundColor = 'red';
+ // }, false);
+ // }
- for (var i = 0; i < els.length; i++) {
- els[i].addEventListener('mouseenter', function() {
- anime.remove(this);
- this.style.backgroundColor = 'red';
- }, false);
- }
+console.log(tl);
</script>
<!-- <script src="../assets/js/vendors/stats.min.js"></script> -->
diff --git a/src/index.js b/src/index.js
index b3b8d2dc..5efddb1a 100644
--- a/src/index.js
+++ b/src/index.js
@@ -980,66 +980,51 @@ function anime(params = {}) {
anim.currentValue = progress;
i++;
}
+ instance.currentTime = insTime;
}
function setCallback(cb) {
if (instance[cb]) instance[cb](instance);
}
+ function countIteration() {
+ if (instance.remaining && instance.remaining !== true) {
+ instance.remaining--;
+ }
+ }
+
function setInstanceProgress(engineTime) {
const insDuration = instance.duration;
const insDelay = instance.delay;
const insEndDelay = insDuration - instance.endDelay;
const insTime = adjustTime(engineTime);
- const insReversed = instance.reversed;
- instance.currentTime = insTime;
+ instance.progress = minMax((insTime / insDuration) * 100, 0, 100);
+ if (children) { syncInstanceChildren(insTime); }
if (!instance.began) {
instance.began = true;
setCallback('begin');
- setCallback('loopBegin');
- }
- if (
- (!instance.changeBegan && !insReversed && insTime >= insDelay && insTime < insEndDelay) ||
- (!instance.changeBegan && insReversed && insTime <= insEndDelay && insTime > insDelay)) {
- instance.changeBegan = true;
- instance.changeCompleted = false;
- setCallback('changeBegin');
}
- if (insTime >= insDelay && insTime < insEndDelay) {
- setAnimationsProgress(insTime);
+ if ((insTime >= insDelay && insTime <= insEndDelay) || !insDuration) {
setCallback('change');
}
- if (
- (!instance.changeCompleted && !insReversed && insTime >= insEndDelay) ||
- (!instance.changeCompleted && insReversed && insTime <= insDelay)) {
- instance.changeCompleted = true;
- instance.changeBegan = false;
- setAnimationsProgress(insReversed ? insDelay : insEndDelay);
- setCallback('changeComplete');
- }
- if (
- (insTime <= 0 && instance.currentTime !== 0 && instance.reversed) ||
- (insTime >= insDuration && instance.currentTime !== insDuration && !instance.reversed)) {
- if (instance.remaining && instance.remaining !== true) {
- instance.remaining--;
+ if (insTime > insDelay && insTime < insDuration) {
+ setAnimationsProgress(insTime);
+ } else {
+ if (insTime <= insDelay && instance.currentTime !== 0) {
+ setAnimationsProgress(0);
+ if (instance.reversed) { countIteration(); }
+ }
+ if ((insTime >= insDuration && instance.currentTime !== insDuration) || !insDuration) {
+ setAnimationsProgress(insDuration);
+ if (!instance.reversed) { countIteration(); }
}
}
- if (insTime <= 0 && instance.currentTime !== 0) {
- instance.currentTime = 0;
- }
- if (insTime >= insDuration && instance.currentTime !== insDuration) {
- instance.currentTime = insDuration;
- }
- if (children) syncInstanceChildren(instance.currentTime);
- instance.progress = (instance.currentTime / insDuration) * 100;
setCallback('update');
if (engineTime >= insDuration) {
lastTime = 0;
- setCallback('loopComplete');
if (instance.remaining) {
- setCallback('loopBegin');
startTime = now;
- if (instance.direction === 'alternate') toggleInstanceDirection();
+ if (instance.direction === 'alternate') { toggleInstanceDirection(); }
} else {
instance.paused = true;
if (!instance.completed) {
@@ -1054,6 +1039,74 @@ function anime(params = {}) {
}
}
+ // function setInstanceProgress(engineTime) {
+ // const insDuration = instance.duration;
+ // const insDelay = instance.delay;
+ // const insEndDelay = insDuration - instance.endDelay;
+ // const insTime = adjustTime(engineTime);
+ // const insReversed = instance.reversed;
+ // instance.currentTime = insTime;
+ // if (!instance.began) {
+ // instance.began = true;
+ // setCallback('begin');
+ // setCallback('loopBegin');
+ // }
+ // if (
+ // (!instance.changeBegan && !insReversed && insTime >= insDelay && insTime < insEndDelay) ||
+ // (!instance.changeBegan && insReversed && insTime <= insEndDelay && insTime > insDelay)) {
+ // instance.changeBegan = true;
+ // instance.changeCompleted = false;
+ // setCallback('changeBegin');
+ // }
+ // if (insTime >= insDelay && insTime < insEndDelay) {
+ // setAnimationsProgress(insTime);
+ // setCallback('change');
+ // }
+ // if (
+ // (!instance.changeCompleted && !insReversed && insTime >= insEndDelay) ||
+ // (!instance.changeCompleted && insReversed && insTime <= insDelay)) {
+ // instance.changeCompleted = true;
+ // instance.changeBegan = false;
+ // setAnimationsProgress(insReversed ? insDelay : insEndDelay);
+ // setCallback('changeComplete');
+ // }
+ // if (
+ // (insTime <= 0 && instance.currentTime !== 0 && instance.reversed) ||
+ // (insTime >= insDuration && instance.currentTime !== insDuration && !instance.reversed)) {
+ // if (instance.remaining && instance.remaining !== true) {
+ // instance.remaining--;
+ // }
+ // }
+ // if (insTime <= 0 && instance.currentTime !== 0) {
+ // instance.currentTime = 0;
+ // }
+ // if (insTime >= insDuration && instance.currentTime !== insDuration) {
+ // instance.currentTime = insDuration;
+ // }
+ // if (children) syncInstanceChildren(instance.currentTime);
+ // instance.progress = (instance.currentTime / insDuration) * 100;
+ // setCallback('update');
+ // if (engineTime >= insDuration) {
+ // lastTime = 0;
+ // setCallback('loopComplete');
+ // if (instance.remaining) {
+ // setCallback('loopBegin');
+ // startTime = now;
+ // if (instance.direction === 'alternate') toggleInstanceDirection();
+ // } else {
+ // instance.paused = true;
+ // if (!instance.completed) {
+ // instance.completed = true;
+ // setCallback('complete');
+ // if ('Promise' in window) {
+ // resolve();
+ // promise = makePromise();
+ // }
+ // }
+ // }
+ // }
+ // }
+
instance.reset = function() {
const direction = instance.direction;
const loops = instance.loop;