JavaScript animation engine
Revert "Initial remove() refactoring code"
Julian Garnier259c66bdc4ab
diff --git a/anime.js b/anime.jsindex a126603f..6a242dcf 100644--- a/anime.js+++ b/anime.js@@ -32,7 +32,6 @@loop: 1,direction: 'normal',autoplay: true,- replace: true,offset: 0}@@ -642,73 +641,14 @@}}- // Remove targets from animation-- // function removeAnimation(targets, property) {- // const targetsArray = parseTargets(targets);- // for (let i = activeInstances.length; i--;) {- // const instance = activeInstances[i];- // const animations = instance.animations;- // for (let a = animations.length; a--;) {- // if (arrayContains(targetsArray, animations[a].animatable.target)) {- // animations.splice(a, 1);- // if (!animations.length) instance.pause();- // }- // }- // }- // }-- function removeAnimation(target, propertyName) {- // const targetsArray = parseTargets(targets);- for (let i = activeInstances.length; i--;) {- const instance = activeInstances[i];- const animations = instance.animations;- for (let a = animations.length; a--;) {- const animation = animations[a];- if ((propertyName && (animation.property === propertyName)) && instance.animatables.some(t => t.target === target)) {- animations.splice(a, 1);- if (!animations.length) instance.pause();- }- }- }- }-- function removeTargets(targets) {- const targetsArray = parseTargets(targets);- for (let i = targets.length; i--;) {- removeAnimation(targets[i]);- }- }-- function getAnimations(animatables, properties, replace) {+ function getAnimations(animatables, properties) {return filterArray(flattenArray(animatables.map(animatable => {return properties.map(prop => {- if (replace) removeAnimation(animatable.target, prop.name);return createAnimation(animatable, prop);});})), a => !is.und(a));}- // function getAnimations(animatables, properties) {- // return filterArray(flattenArray(animatables.map(animatable => {- // return properties.map(prop => {- // const target = animatable.target;- // for (let i = activeInstances.length; i--;) {- // const instance = activeInstances[i];- // const animations = activeInstances[i].animations;- // for (let a = animations.length; a--;) {- // const animation = animations[a];- // if ((animation.property === prop.name) && instance.animatables.some(t => t.target === target)) {- // animations.splice(a, 1);- // if (!animations.length) instance.pause();- // }- // }- // }- // return createAnimation(animatable, prop);- // });- // })), a => !is.und(a));- // }-// Create Instancefunction getInstanceTimings(type, animations, instanceSettings, tweenSettings) {@@ -725,7 +665,7 @@const tweenSettings = replaceObjectProps(defaultTweenSettings, params);const animatables = getAnimatables(params.targets);const properties = getProperties(instanceSettings, tweenSettings, params);- const animations = getAnimations(animatables, properties, instanceSettings.replace);+ const animations = getAnimations(animatables, properties);return mergeObjects(instanceSettings, {children: [],animatables: animatables,@@ -759,21 +699,6 @@return play;})();- // Remove targets from animation-- // function removeTargets(targets) {- // const targetsArray = parseTargets(targets);- // for (let i = activeInstances.length; i--;) {- // const instance = activeInstances[i];- // const animations = instance.animations;- // for (let a = animations.length; a--;) {- // if (arrayContains(targetsArray, animations[a].animatable.target)) {- // animations.splice(a, 1);- // if (!animations.length) instance.pause();- // }- // }- // }- // }// Public Instance@@ -995,8 +920,6 @@instance.finished = promise;- // if (instance.replace) removeTargets(params.targets);-instance.reset();if (instance.autoplay) instance.play();@@ -1005,6 +928,22 @@}+ // Remove targets from animation++ function removeTargets(targets) {+ const targetsArray = parseTargets(targets);+ for (let i = activeInstances.length; i--;) {+ const instance = activeInstances[i];+ const animations = instance.animations;+ for (let a = animations.length; a--;) {+ if (arrayContains(targetsArray, animations[a].animatable.target)) {+ animations.splice(a, 1);+ if (!animations.length) instance.pause();+ }+ }+ }+ }+// Timelinefunction timeline(params = {}) {diff --git a/documentation/examples/anime-DOM-stress-test-02.html b/documentation/examples/anime-DOM-stress-test-02.htmlindex 5e70e9bc..0090865f 100644--- a/documentation/examples/anime-DOM-stress-test-02.html+++ b/documentation/examples/anime-DOM-stress-test-02.html@@ -17,7 +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.2.0.js"></script> -->+ <!-- <script src="../assets/js/anime.2.0.2.js"></script> --><!-- <script src="../assets/js/anime.1.0.js"></script> --><style>diff --git a/documentation/examples/anime-speed-test.html b/documentation/examples/anime-speed-test.htmlindex 972956e9..d56b2a82 100644--- a/documentation/examples/anime-speed-test.html+++ b/documentation/examples/anime-speed-test.html@@ -17,7 +17,6 @@<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.2.0.js"></script> --><!-- <script src="../assets/js/anime.2.1.0.js"></script> --><!-- <script src="../assets/js/anime.2.0.1.js"></script> --><!-- <script src="../assets/js/anime.1.3.js"></script> -->diff --git a/documentation/examples/anime-tests.html b/documentation/examples/anime-tests.htmlindex 65425300..1a5e65ba 100644--- a/documentation/examples/anime-tests.html+++ b/documentation/examples/anime-tests.html@@ -41,39 +41,10 @@<div class="item color-02"></div><div class="item color-03"></div><script>- var anim = anime({- targets: '.color-01',- backgroundColor: '#BAD',- direction: 'alternate',- easing: 'linear',- translateX: 50,- loop: true- });- var anim = anime({- targets: '.color-02',- scale: 2,- opacity: .5,- loop: true- });- console.log(anim);- function mouseenter(e) {- var anim = anime({- targets: this,- scale: 2,- opacity: .5- });- console.log(anim);- }- function mouseleave(e) {- anime({- targets: this,- scale: 1,- opacity: 1- })- }- var el = document.querySelector('.color-01');- el.addEventListener('mouseenter', mouseenter, false);- el.addEventListener('mouseleave', mouseleave, false);+ var tl = anime.timeline();+ tl.add({+ translateX: 100+ })</script></body></html>\ No newline at end of file