JavaScript animation engine
#121
Julian Garniera3dbe9211569
diff --git a/anime.js b/anime.jsindex 52e05979..626e22d4 100644--- a/anime.js+++ b/anime.js@@ -682,7 +682,11 @@function syncInstanceChildren(time) {const children = instance.children;- for (let i = 0; i < arrayLength(children); i++) children[i].seek(time);+ if (time >= instance.currentTime) {+ for (let i = 0; i < arrayLength(children); i++) children[i].seek(time);+ } else {+ for (let i = arrayLength(children); i--;) children[i].seek(time);+ }}function setAnimationsProgress(insTime) {@@ -739,6 +743,7 @@const insCurrentTime = instance.currentTime;const insReversed = instance.reversed;const insTime = minMaxValue(adjustTime(engineTime), 0, insDuration);+ if (instance.children) syncInstanceChildren(insTime);if (insTime > insOffset && insTime < insDuration) {setAnimationsProgress(insTime);if (!instance.began && insTime >= insDelay) {@@ -771,7 +776,6 @@}lastTime = 0;}- if (instance.children) syncInstanceChildren(insTime);setCallback('update');}@@ -796,12 +800,7 @@if (!instance.paused) return;instance.paused = false;startTime = 0;- if (instance.completed) {- instance.reset();- lastTime = 0;- } else {- lastTime = adjustTime(instance.currentTime);- }+ lastTime = adjustTime(instance.currentTime);activeInstances.push(instance);if (!raf) engine();}@@ -832,10 +831,10 @@function removeTargets(targets) {const targetsArray = parseTargets(targets);- for (let i = arrayLength(activeInstances)-1; i >= 0; i--) {+ for (let i = arrayLength(activeInstances); i--;) {const instance = activeInstances[i];const animations = instance.animations;- for (let a = arrayLength(animations)-1; a >= 0; a--) {+ for (let a = arrayLength(animations); a--;) {if (arrayContains(targetsArray, animations[a].animatable.target)) {animations.splice(a, 1);if (!arrayLength(animations)) instance.pause();@@ -864,7 +863,8 @@tl.children.push(ins);});tl.reset();- if (tl.autoplay) tl.play();+ tl.seek(0);+ if (tl.autoplay) tl.restart();return tl;}return tl;diff --git a/documentation/examples/anime-timeline.html b/documentation/examples/anime-timeline.htmlindex d17f3db9..d03c1ec3 100644--- a/documentation/examples/anime-timeline.html+++ b/documentation/examples/anime-timeline.html@@ -17,6 +17,7 @@<link rel="icon" type="image/png" href="../assets/img/icons/favicon.png" ><link href="../assets/css/anime.css" rel="stylesheet"><script src="../../anime.js"></script>+ <!-- <script src="../assets/js/anime.2.0.1.js"></script> --><style>body {@@ -68,9 +69,9 @@</style></head><body>- <div class="el no-offset"></div>+<!-- <div class="el no-offset"></div><div class="el relative-offset"></div>- <div class="el absolute-offset"></div>+ <div class="el absolute-offset"></div> --><div class="el multiple-targets-01"></div><div class="el multiple-targets-02"></div><div class="el multiple-targets-03"></div>@@ -90,159 +91,158 @@</body><script>- var noOffset = anime.timeline({- autoplay: true- });+ // var noOffset = anime.timeline({+ // autoplay: true+ // });- noOffset- .add({- targets: '.no-offset',- translateX: -100,- translateY: -100,- scale: 2,- background: '#FF1461',- begin: function() { console.log('noOffset animation 1 began')},- complete: function() { console.log('noOffset animation 1 completed')}- })- .add({- targets: '.no-offset',- translateX: -100,- translateY: 100,- scale: 3,- background: '#18FF92',- begin: function() { console.log('noOffset animation 2 began')},- complete: function() { console.log('noOffset animation 2 completed')}- })- .add({- targets: '.no-offset',- translateX: 100,- translateY: 100,- rotate: 120,- scale: 4,- background: '#5A87FF',- begin: function() { console.log('noOffset animation 3 began')},- complete: function() { console.log('noOffset animation 3 completed')}- })- .add({- targets: '.no-offset',- translateX: 100,- translateY: -100,- scale: 5,- background: '#FBF38C',- begin: function() { console.log('noOffset animation 4 began')},- complete: function() { console.log('noOffset animation 4 completed')}- })- .add({- targets: '.no-offset',- translateX: 100,- translateY: -100,- scale: '+=8',- background: '#FBF38C',- begin: function() { console.log('noOffset animation 5 began')},- complete: function() { console.log('noOffset animation 5 completed')}- });+ // noOffset+ // .add({+ // targets: '.no-offset',+ // translateX: -100,+ // translateY: -100,+ // scale: 2,+ // background: '#FF1461',+ // begin: function() { console.log('noOffset animation 1 began')},+ // complete: function() { console.log('noOffset animation 1 completed')}+ // })+ // .add({+ // targets: '.no-offset',+ // translateX: -100,+ // translateY: 100,+ // scale: 3,+ // background: '#18FF92',+ // begin: function() { console.log('noOffset animation 2 began')},+ // complete: function() { console.log('noOffset animation 2 completed')}+ // })+ // .add({+ // targets: '.no-offset',+ // translateX: 100,+ // translateY: 100,+ // rotate: 120,+ // scale: 4,+ // background: '#5A87FF',+ // begin: function() { console.log('noOffset animation 3 began')},+ // complete: function() { console.log('noOffset animation 3 completed')}+ // })+ // .add({+ // targets: '.no-offset',+ // translateX: 100,+ // translateY: -100,+ // scale: 5,+ // background: '#FBF38C',+ // begin: function() { console.log('noOffset animation 4 began')},+ // complete: function() { console.log('noOffset animation 4 completed')}+ // })+ // .add({+ // targets: '.no-offset',+ // translateX: 100,+ // translateY: -100,+ // scale: '+=8',+ // background: '#FBF38C',+ // begin: function() { console.log('noOffset animation 5 began')},+ // complete: function() { console.log('noOffset animation 5 completed')}+ // });- var relativeOffset = anime.timeline();+ // var relativeOffset = anime.timeline();- relativeOffset- .add({- targets: '.relative-offset',- translateX: -100,- translateY: -100,- scale: 2,- background: '#FF1461',- })- .add({- targets: '.relative-offset',- translateX: -100,- translateY: 100,- scale: 3,- background: '#18FF92',- offset: '-=500'- })- .add({- targets: '.relative-offset',- translateX: 100,- translateY: 100,- rotate: 120,- scale: 4,- background: '#5A87FF',- offset: '-=500'- })- .add({- targets: '.relative-offset',- translateX: 100,- translateY: -100,- scale: 5,- background: '#FBF38C',- offset: '+=500'- })- .add({- targets: '.relative-offset',- translateX: 100,- translateY: -100,- scale: '+=8',- background: '#FBF38C',- offset: '+=500'- });+ // relativeOffset+ // .add({+ // targets: '.relative-offset',+ // translateX: -100,+ // translateY: -100,+ // scale: 2,+ // background: '#FF1461',+ // })+ // .add({+ // targets: '.relative-offset',+ // translateX: -100,+ // translateY: 100,+ // scale: 3,+ // background: '#18FF92',+ // offset: '-=500'+ // })+ // .add({+ // targets: '.relative-offset',+ // translateX: 100,+ // translateY: 100,+ // rotate: 120,+ // scale: 4,+ // background: '#5A87FF',+ // offset: '-=500'+ // })+ // .add({+ // targets: '.relative-offset',+ // translateX: 100,+ // translateY: -100,+ // scale: 5,+ // background: '#FBF38C',+ // offset: '+=500'+ // })+ // .add({+ // targets: '.relative-offset',+ // translateX: 100,+ // translateY: -100,+ // scale: '+=8',+ // background: '#FBF38C',+ // offset: '+=500'+ // });- var absoluteOffset = anime.timeline();+ // var absoluteOffset = anime.timeline();- absoluteOffset- .add({- targets: '.absolute-offset',- translateX: -100,- translateY: -100,- scale: 2,- background: '#FF1461',- offset: 0- })- .add({- targets: '.absolute-offset',- translateX: -100,- translateY: 100,- scale: 3,- background: '#18FF92',- offset: 1000- })- .add({- targets: '.absolute-offset',- translateX: 100,- translateY: 100,- rotate: 120,- scale: 4,- background: '#5A87FF',- offset: 2000- })- .add({- targets: '.absolute-offset',- translateX: 100,- translateY: -100,- scale: 5,- background: '#FBF38C',- offset: 3000- })- .add({- targets: '.absolute-offset',- translateX: 100,- translateY: -100,- scale: '+=8',- background: '#FBF38C',- offset: 4000- });+ // absoluteOffset+ // .add({+ // targets: '.absolute-offset',+ // translateX: -100,+ // translateY: -100,+ // scale: 2,+ // background: '#FF1461',+ // offset: 0+ // })+ // .add({+ // targets: '.absolute-offset',+ // translateX: -100,+ // translateY: 100,+ // scale: 3,+ // background: '#18FF92',+ // offset: 1000+ // })+ // .add({+ // targets: '.absolute-offset',+ // translateX: 100,+ // translateY: 100,+ // rotate: 120,+ // scale: 4,+ // background: '#5A87FF',+ // offset: 2000+ // })+ // .add({+ // targets: '.absolute-offset',+ // translateX: 100,+ // translateY: -100,+ // scale: 5,+ // background: '#FBF38C',+ // offset: 3000+ // })+ // .add({+ // targets: '.absolute-offset',+ // translateX: 100,+ // translateY: -100,+ // scale: '+=8',+ // background: '#FBF38C',+ // offset: 4000+ // });var controlsProgressEl = document.querySelector('.controls .progress');var multipleTargets = anime.timeline({- autoplay: true,- direction: 'false',+ autoplay: false,+ loop: true,+ direction: 'normal',update: function(anim) {controlsProgressEl.value = anim.progress;}});- multipleTargets.tracker = 'YA';-document.querySelector('.controls .play').onclick = multipleTargets.play;document.querySelector('.controls .pause').onclick = multipleTargets.pause;document.querySelector('.controls .restart').onclick = multipleTargets.restart;@@ -253,6 +253,7 @@translateY: -100,scale: 8,background: '#FF1461',+ duration: 500,begin: function() { console.log('multipleTargets animation 1 began')},complete: function() { console.log('multipleTargets animation 1 completed')}})@@ -261,6 +262,7 @@translateY: -100,scale: 8,background: '#18FF92',+ duration: 500,begin: function() { console.log('multipleTargets animation 2 began')},complete: function() { console.log('multipleTargets animation 2 completed')}})@@ -269,6 +271,7 @@translateY: -100,scale: 8,background: '#5A87FF',+ duration: 500,begin: function() { console.log('multipleTargets animation 3 began')},complete: function() { console.log('multipleTargets animation 3 completed')}})@@ -277,6 +280,7 @@translateY: -100,scale: 8,background: '#FBF38C',+ duration: 500,begin: function() { console.log('multipleTargets animation 4 began')},complete: function() { console.log('multipleTargets animation 4 completed')}})@@ -285,6 +289,7 @@translateY: -100,scale: 13,background: '#FBF38C',+ duration: 1000,begin: function() { console.log('multipleTargets animation 5 began')},complete: function() { console.log('multipleTargets animation 5 completed')}});