JavaScript animation engine
Clean up
Julian Garniereb4c1c321ceb
diff --git a/anime.js b/anime.jsindex 8ce2a716..0979cb35 100644--- a/anime.js+++ b/anime.js@@ -65,7 +65,6 @@}// BezierEasing https://github.com/gre/bezier-easing- // © 2014 Gaëtan Renaudeau – MIT Licenseconst bezier = (() => {@@ -161,7 +160,6 @@}// Approximated Penner equations http://matthewlein.com/ceaser/- // © Matthew Leinconst equations = {In: [@@ -435,7 +433,6 @@}// Decompose / recompose functions adapted from Animate Plus https://github.com/bendc/animateplus- // © 2015 Benjamin De Cockfunction decomposeValue(val, unit) {const rgx = /-?\d*\.?\d+/g;@@ -654,7 +651,7 @@function getInstanceTimings(type, animations, tweenSettings) {const math = (type === 'delay') ? Math.min : Math.max;- return arrayLength(animations) ? math.apply(Math, animations.map((anim) => anim[type] )) : tweenSettings[type];+ return arrayLength(animations) ? math.apply(Math, animations.map((anim) => anim[type])) : tweenSettings[type];}function createNewInstance(params = {}) {@@ -674,7 +671,7 @@began: false,completed: false,remaining: instanceSettings.loop- })+ });}// Corediff --git a/examples/ease-visualizer.html b/examples/ease-visualizer.htmlindex 82e5aa9b..7ad74f8f 100644--- a/examples/ease-visualizer.html+++ b/examples/ease-visualizer.html@@ -43,6 +43,7 @@background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;}.visualizer-wrapper {+ position: relative;width: 200px;height: 200px;}@@ -83,14 +84,29 @@margin-left: 40px;}}+ .axis {+ position: absolute;+ background: #5A87FF;+ }+ .axis.x {+ width: 1px;+ height: 100%;+ transform-origin: 0 0;+ }+ .axis.y {+ bottom: 0;+ width: 100%;+ height: 1px;+ transform-origin: 100% 0;+ }.ball {position: absolute;z-index: 2;top: 0;- left: 0;+ left: 100%;width: 10px;height: 10px;- margin: -5px 0 0 -5px;+ margin: -5px 0 0 10px;background: #FF1461;border-radius: 50%;}@@ -102,7 +118,7 @@width: 10px;height: 1px;margin: -1px 0 0 10px;- background: #5A87FF;+ background: #FF1461;}.onion {opacity: .2;@@ -159,14 +175,10 @@<div class="easings"><div class="output"><div class="visualizer-wrapper grid">+ <div class="axis x"></div>+ <div class="axis y"></div><div class="visualizer"><div class="ball"></div>- <div class="rec"></div>- <div class="rec onion"></div>- <div class="rec onion"></div>- <div class="rec onion"></div>- <div class="rec onion"></div>- <div class="rec onion"></div><svg viewBox="0 0 100 100"><path class="curve"/></svg>@@ -176,32 +188,32 @@</div><div class="options"><label>Ease In</label>- <button class="active" value="0.550, 0.085, 0.680, 0.530">Quad</button>- <button value="0.550, 0.055, 0.675, 0.190">Cubic</button>- <button value="0.895, 0.030, 0.685, 0.220">Quart</button>- <button value="0.755, 0.050, 0.855, 0.060">Quint</button>- <button value="0.470, 0.000, 0.745, 0.715">Sine</button>- <button value="0.950, 0.050, 0.795, 0.035">Expo</button>- <button value="0.600, 0.040, 0.980, 0.335">Circ</button>- <button value="0.600, -0.280, 0.735, 0.045">Back</button>+ <button class="active" value="0.550, 0.085, 0.680, 0.530" name="easeInQuad" >Quad</button>+ <button value="0.550, 0.055, 0.675, 0.190" name="easeInCubic" >Cubic</button>+ <button value="0.895, 0.030, 0.685, 0.220" name="easeInQuart" >Quart</button>+ <button value="0.755, 0.050, 0.855, 0.060" name="easeInQuint" >Quint</button>+ <button value="0.470, 0.000, 0.745, 0.715" name="easeInSine" >Sine</button>+ <button value="0.950, 0.050, 0.795, 0.035" name="easeInExpo" >Expo</button>+ <button value="0.600, 0.040, 0.980, 0.335" name="easeInCirc" >Circ</button>+ <button value="0.600, -0.280, 0.735, 0.045" name="easeInBack" >Back</button><label>Ease Out</label>- <button value="0.250, 0.460, 0.450, 0.940">Quad</button>- <button value="0.215, 0.610, 0.355, 1.000">Cubic</button>- <button value="0.165, 0.840, 0.440, 1.000">Quart</button>- <button value="0.230, 1.000, 0.320, 1.000">Quint</button>- <button value="0.390, 0.575, 0.565, 1.000">Sine</button>- <button value="0.190, 1.000, 0.220, 1.000">Expo</button>- <button value="0.075, 0.820, 0.165, 1.000">Circ</button>- <button value="0.175, 0.885, 0.320, 1.275">Back</button>+ <button value="0.250, 0.460, 0.450, 0.940" name="easeOutQuad" >Quad</button>+ <button value="0.215, 0.610, 0.355, 1.000" name="easeOutCubic" >Cubic</button>+ <button value="0.165, 0.840, 0.440, 1.000" name="easeOutQuart" >Quart</button>+ <button value="0.230, 1.000, 0.320, 1.000" name="easeOutQuint" >Quint</button>+ <button value="0.390, 0.575, 0.565, 1.000" name="easeOutSine" >Sine</button>+ <button value="0.190, 1.000, 0.220, 1.000" name="easeOutExpo" >Expo</button>+ <button value="0.075, 0.820, 0.165, 1.000" name="easeOutCirc" >Circ</button>+ <button value="0.175, 0.885, 0.320, 1.275" name="easeOutBack" >Back</button><label>Ease In Out</label>- <button value="0.455, 0.030, 0.515, 0.955">Quad</button>- <button value="0.645, 0.045, 0.355, 1.000">Cubic</button>- <button value="0.770, 0.000, 0.175, 1.000">Quart</button>- <button value="0.860, 0.000, 0.070, 1.000">Quint</button>- <button value="0.445, 0.050, 0.550, 0.950">Sine</button>- <button value="1.000, 0.000, 0.000, 1.000">Expo</button>- <button value="0.785, 0.135, 0.150, 0.860">Circ</button>- <button value="0.680, -0.550, 0.265, 1.550">Back</button>+ <button value="0.455, 0.030, 0.515, 0.955" name="easeInOutQuad" >Quad</button>+ <button value="0.645, 0.045, 0.355, 1.000" name="easeInOutCubic" >Cubic</button>+ <button value="0.770, 0.000, 0.175, 1.000" name="easeInOutQuart" >Quart</button>+ <button value="0.860, 0.000, 0.070, 1.000" name="easeInOutQuint" >Quint</button>+ <button value="0.445, 0.050, 0.550, 0.950" name="easeInOutSine" >Sine</button>+ <button value="1.000, 0.000, 0.000, 1.000" name="easeInOutExpo" >Expo</button>+ <button value="0.785, 0.135, 0.150, 0.860" name="easeInOutCirc" >Circ</button>+ <button value="0.680, -0.550, 0.265, 1.550" name="easeInOutBack" >Back</button></div></div><script>@@ -209,6 +221,62 @@var pathEl = document.querySelector('.curve');var presetsEls = document.querySelectorAll('.options button');+ function animateProgress(easingName) {++ var timeline = anime.timeline({+ loop: true+ });++ var path = anime.path(pathEl, 100);++ anime.remove(['.ball', '.rec']);++ timeline.add([+ // anime({+ // targets: '.ball',+ // translateX: path('x'),+ // translateY: path('y'),+ // scale: [+ // { value: [0, 1], delay: 0, duration: 500, easing: 'easeOutBack' },+ // { value: 0, delay: 1000, duration: 500, easing: 'easeInBack' }+ // ],+ // easing: easingName,+ // delay: 500+ // }),+ anime({+ targets: '.axis.x',+ translateX: [0, 400],+ easing: 'linear',+ scale: [+ { value: [0, 1], delay: 0, duration: 500, easing: 'easeOutQuad' },+ { value: 0, delay: 1000, duration: 500, easing: 'easeInQuad' }+ ],+ delay: 500+ }),+ anime({+ targets: '.axis.y',+ translateY: [0, -400],+ easing: easingName,+ scale: [+ { value: [0, 1], delay: 0, duration: 500, easing: 'easeOutQuad' },+ { value: 0, delay: 1000, duration: 500, easing: 'easeInQuad' }+ ],+ delay: 500+ }),+ anime({+ targets: '.ball',+ translateY: [100, 0],+ easing: easingName,+ scale: [+ { value: [0, 1], delay: 0, duration: 500, easing: 'easeOutBack' },+ { value: 0, delay: 1000, duration: 500, easing: 'easeInBack' }+ ],+ delay: 500+ })+ ]);++ }+function convertCoordinates(coords) {var x1 = coords[0] * 100;var y1 = 100 - (coords[1] * 100);@@ -227,8 +295,10 @@}var buttonEl = event.target;var value = buttonEl.value;+ var name = buttonEl.name;buttonEl.classList.add('active');var coordinates = getCoordinates(value);+ animateProgress(name);anime.remove(pathEl);anime({targets: pathEl,@@ -242,39 +312,6 @@pathEl.setAttribute('d', getCoordinates(presetsEls[23].value));- var timeline = anime.timeline({- loop: true- });-- var path = anime.path(pathEl, 100);-- var ballAnim = anime({- targets: '.ball',- translateX: path('x'),- translateY: path('y'),- scale: [- { value: [0, 1], delay: 0, duration: 500, easing: 'easeOutBack' },- { value: 0, delay: 1000, duration: 500, easing: 'easeInBack' }- ],- easing: 'linear',- delay: 500- });-- var recAnim = anime({- targets: '.rec',- translateY: path('y'),- easing: 'linear',- scaleY: [- { value: [0, 1], delay: 0, duration: 500, easing: 'easeOutBack' },- { value: 0, delay: 1000, duration: 500, easing: 'easeInBack' }- ],- delay: function(el, i) {- return 500 + (i * 20);- }- });-- timeline.add([ballAnim, recAnim]);-pathEl.setAttribute('d', getCoordinates(presetsEls[0].value));</script>