JavaScript animation engine
Initial remove() refactoring code
Julian Garnier029c50e13b5e
diff --git a/anime.js b/anime.jsindex 6a242dcf..a126603f 100644--- a/anime.js+++ b/anime.js@@ -32,6 +32,7 @@loop: 1,direction: 'normal',autoplay: true,+ replace: true,offset: 0}@@ -641,14 +642,73 @@}}- function getAnimations(animatables, properties) {+ // 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) {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) {@@ -665,7 +725,7 @@const tweenSettings = replaceObjectProps(defaultTweenSettings, params);const animatables = getAnimatables(params.targets);const properties = getProperties(instanceSettings, tweenSettings, params);- const animations = getAnimations(animatables, properties);+ const animations = getAnimations(animatables, properties, instanceSettings.replace);return mergeObjects(instanceSettings, {children: [],animatables: animatables,@@ -699,6 +759,21 @@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@@ -920,6 +995,8 @@instance.finished = promise;+ // if (instance.replace) removeTargets(params.targets);+instance.reset();if (instance.autoplay) instance.play();@@ -928,22 +1005,6 @@}- // 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 0090865f..5e70e9bc 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.0.2.js"></script> -->+ <!-- <script src="../assets/js/anime.2.2.0.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 d56b2a82..972956e9 100644--- a/documentation/examples/anime-speed-test.html+++ b/documentation/examples/anime-speed-test.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.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 1a5e65ba..65425300 100644--- a/documentation/examples/anime-tests.html+++ b/documentation/examples/anime-tests.html@@ -41,10 +41,39 @@<div class="item color-02"></div><div class="item color-03"></div><script>- var tl = anime.timeline();- tl.add({- translateX: 100- })+ 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);</script></body></html>\ No newline at end of file