JavaScript animation engine
Update examples and tests
Julian Garnier8c4678d467ce
diff --git a/documentation/assets/js/anime.2.0.2.js b/documentation/assets/js/anime.2.0.2.jsindex ac408dda..4aaaaf6b 100644--- a/documentation/assets/js/anime.2.0.2.js+++ b/documentation/assets/js/anime.2.0.2.js@@ -1,27 +1,875 @@-/*- 2017 Julian Garnier- Released under the MIT license-*/-var $jscomp$this=this;-(function(v,p){"function"===typeof define&&define.amd?define([],p):"object"===typeof module&&module.exports?module.exports=p():v.anime=p()})(this,function(){function v(a){if(!g.col(a))try{return document.querySelectorAll(a)}catch(b){}}function p(a){return a.reduce(function(a,d){return a.concat(g.arr(d)?p(d):d)},[])}function w(a){if(g.arr(a))return a;g.str(a)&&(a=v(a)||a);return a instanceof NodeList||a instanceof HTMLCollection?[].slice.call(a):[a]}function F(a,b){return a.some(function(a){return a===b})}-function A(a){var b={},d;for(d in a)b[d]=a[d];return b}function G(a,b){var d=A(a),c;for(c in a)d[c]=b.hasOwnProperty(c)?b[c]:a[c];return d}function B(a,b){var d=A(a),c;for(c in b)d[c]=g.und(a[c])?b[c]:a[c];return d}function S(a){a=a.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(a,b,d,h){return b+b+d+d+h+h});var b=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);a=parseInt(b[1],16);var d=parseInt(b[2],16),b=parseInt(b[3],16);return"rgb("+a+","+d+","+b+")"}function T(a){function b(a,b,c){0>-c&&(c+=1);1<c&&--c;return c<1/6?a+6*(b-a)*c:.5>c?b:c<2/3?a+(b-a)*(2/3-c)*6:a}var d=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(a);a=parseInt(d[1])/360;var c=parseInt(d[2])/100,d=parseInt(d[3])/100;if(0==c)c=d=a=d;else{var e=.5>d?d*(1+c):d+c-d*c,l=2*d-e,c=b(l,e,a+1/3),d=b(l,e,a);a=b(l,e,a-1/3)}return"rgb("+255*c+","+255*d+","+255*a+")"}function x(a){if(a=/([\+\-]?[0-9#\.]+)(%|px|pt|em|rem|in|cm|mm|ex|pc|vw|vh|deg|rad|turn)?/.exec(a))return a[2]}function U(a){if(-1<a.indexOf("translate"))return"px";-if(-1<a.indexOf("rotate")||-1<a.indexOf("skew"))return"deg"}function H(a,b){return g.fnc(a)?a(b.target,b.id,b.total):a}function C(a,b){if(b in a.style)return getComputedStyle(a).getPropertyValue(b.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase())||"0"}function I(a,b){if(g.dom(a)&&F(V,b))return"transform";if(g.dom(a)&&(a.getAttribute(b)||g.svg(a)&&a[b]))return"attribute";if(g.dom(a)&&"transform"!==b&&C(a,b))return"css";if(null!=a[b])return"object"}function W(a,b){var d=U(b),d=-1<b.indexOf("scale")?-1:0+d;a=a.style.transform;if(!a)return d;for(var c=[],e=[],l=[],h=/(\w+)\((.+?)\)/g;c=h.exec(a);)e.push(c[1]),l.push(c[2]);a=l.filter(function(a,c){return e[c]===b});return a.length?a[0]:d}function J(a,b){switch(I(a,b)){case "transform":return W(a,b);case "css":return C(a,b);case "attribute":return a.getAttribute(b)}return a[b]||0}function K(a,b){var d=/^(\*=|\+=|-=)/.exec(a);if(!d)return a;b=parseFloat(b);a=parseFloat(a.replace(d[0],""));switch(d[0][0]){case "+":return b+a;case "-":return b-a;case "*":return b*-a}}function D(a){return g.obj(a)&&a.hasOwnProperty("totalLength")}function X(a,b){function d(c){c=void 0===c?0:c;return a.el.getPointAtLength(1<=b+c?b+c:0)}var c=d(),e=d(-1),l=d(1);switch(a.property){case "x":return c.x;case "y":return c.y;case "angle":return 180*Math.atan2(l.y-e.y,l.x-e.x)/Math.PI}}function L(a,b){var d=/-?\d*\.?\d+/g;a=D(a)?a.totalLength:a;if(g.col(a))b=g.rgb(a)?a:g.hex(a)?S(a):g.hsl(a)?T(a):void 0;else{var c=x(a);a=c?a.substr(0,a.length-c.length):a;b=b?a+b:a}b+="";return{original:b,-numbers:b.match(d)?b.match(d).map(Number):[0],strings:b.split(d)}}function Y(a,b){return b.reduce(function(b,c,e){return b+a[e-1]+c})}function M(a){return(a?p(g.arr(a)?a.map(w):w(a)):[]).filter(function(a,d,c){return c.indexOf(a)===d})}function Z(a){var b=M(a);return b.map(function(a,c){return{target:a,id:c,total:b.length}})}function aa(a,b){var d=A(b);if(g.arr(a)){var c=a.length;2!==c||g.obj(a[0])?g.fnc(b.duration)||(d.duration=b.duration/c):a={value:a}}return w(a).map(function(a,c){c=c?0:b.delay;-a=g.obj(a)&&!D(a)?a:{value:a};g.und(a.delay)&&(a.delay=c);return a}).map(function(a){return B(a,d)})}function ba(a,b){var d={},c;for(c in a){var e=H(a[c],b);g.arr(e)&&(e=e.map(function(a){return H(a,b)}),1===e.length&&(e=e[0]));d[c]=e}d.duration=parseFloat(d.duration);d.delay=parseFloat(d.delay);return d}function ca(a){return g.arr(a)?y.apply(this,a):N[a]}function da(a,b){var d;return a.tweens.map(function(c){c=ba(c,b);var e=c.value,l=J(b.target,a.name),h=d?d.to.original:l,h=g.arr(e)?e[0]:h,m=K(g.arr(e)?-e[1]:e,h),l=x(m)||x(h)||x(l);c.isPath=D(e);c.from=L(h,l);c.to=L(m,l);c.start=d?d.end:a.offset;c.end=c.start+c.delay+c.duration;c.easing=ca(c.easing);c.elasticity=(1E3-Math.min(Math.max(c.elasticity,1),999))/1E3;g.col(c.from.original)&&(c.round=1);return d=c})}function ea(a,b){return p(a.map(function(a){return b.map(function(b){var c=I(a.target,b.name);if(c){var d=da(b,a);b={type:c,property:b.name,animatable:a,tweens:d,duration:d[d.length-1].end,delay:d[0].delay}}else b=void 0;return b})})).filter(function(a){return!g.und(a)})}-function O(a,b,d){var c="delay"===a?Math.min:Math.max;return b.length?c.apply(Math,b.map(function(b){return b[a]})):d[a]}function fa(a){var b=G(ga,a),d=G(ha,a),c=Z(a.targets),e=[],g=B(b,d),h;for(h in a)g.hasOwnProperty(h)||"targets"===h||e.push({name:h,offset:g.offset,tweens:aa(a[h],d)});a=ea(c,e);return B(b,{children:[],animatables:c,animations:a,duration:O("duration",a,d),delay:O("delay",a,d)})}function n(a){function b(){return window.Promise&&new Promise(function(a){return Q=a})}function d(a){return f.reversed?-f.duration-a:a}function c(a){for(var b=0,c={},d=f.animations,e={};b<d.length;){var g=d[b],h=g.animatable,m=g.tweens;e.tween=m.filter(function(b){return a<b.end})[0]||m[m.length-1];e.isPath$1=e.tween.isPath;e.round=e.tween.round;e.eased=e.tween.easing(Math.min(Math.max(a-e.tween.start-e.tween.delay,0),e.tween.duration)/e.tween.duration,e.tween.elasticity);m=Y(e.tween.to.numbers.map(function(a){return function(b,c){c=a.isPath$1?0:a.tween.from.numbers[c];b=c+a.eased*(b-c);a.isPath$1&&(b=X(a.tween.value,-b));a.round&&(b=Math.round(b*a.round)/a.round);return b}}(e)),e.tween.to.strings);ia[g.type](h.target,g.property,m,c,h.id);g.currentValue=m;b++;e={isPath$1:e.isPath$1,tween:e.tween,eased:e.eased,round:e.round}}if(c)for(var k in c)E||(E=C(document.body,"transform")?"transform":"-webkit-transform"),f.animatables[k].target.style[E]=c[k].join(" ");f.currentTime=a;f.progress=a/f.duration*100}function e(a){if(f[a])f[a](f)}function g(){f.remaining&&!0!==f.remaining&&f.remaining--}function h(a){var h=f.duration,-l=f.offset,n=f.delay,P=f.currentTime,q=f.reversed,r=d(a),r=Math.min(Math.max(r,0),h);if(f.children){var p=f.children;if(r>=f.currentTime)for(var u=0;u<p.length;u++)p[u].seek(r);else for(u=p.length;u--;)p[u].seek(r)}r>l&&r<h?(c(r),!f.began&&r>=n&&(f.began=!0,e("begin")),e("run")):(r<=l&&0!==P&&(c(0),q&&g()),r>=h&&P!==h&&(c(h),q||g()));a>=h&&(f.remaining?(t=m,"alternate"===f.direction&&(f.reversed=!f.reversed)):(f.pause(),"Promise"in window&&(Q(),R=b()),f.completed||(f.completed=!0,e("complete"))),-k=0);e("update")}a=void 0===a?{}:a;var m,t,k=0,Q=null,R=b(),f=fa(a);f.reset=function(){var a=f.direction,b=f.loop;f.currentTime=0;f.progress=0;f.paused=!0;f.began=!1;f.completed=!1;f.reversed="reverse"===a;f.remaining="alternate"===a&&1===b?2:b;for(a=f.children.length;a--;)b=f.children[a],b.seek(b.offset),b.reset()};f.tick=function(a){m=a;t||(t=m);h((k+m-t)*n.speed)};f.seek=function(a){h(d(a))};f.pause=function(){var a=q.indexOf(f);-1<a&&q.splice(a,1);f.paused=!0};f.play=function(){f.paused&&(f.paused=-!1,t=0,k=d(f.currentTime),q.push(f),z||ja())};f.reverse=function(){f.reversed=!f.reversed;t=0;k=d(f.currentTime)};f.restart=function(){f.pause();f.reset();f.play()};f.finished=R;f.reset();f.autoplay&&f.play();return f}var ga={update:void 0,begin:void 0,run:void 0,complete:void 0,loop:1,direction:"normal",autoplay:!0,offset:0},ha={duration:1E3,delay:0,easing:"easeOutElastic",elasticity:500,round:0},V="translateX translateY translateZ rotate rotateX rotateY rotateZ scale scaleX scaleY scaleZ skewX skewY".split(" "),-E,g={arr:function(a){return Array.isArray(a)},obj:function(a){return-1<Object.prototype.toString.call(a).indexOf("Object")},svg:function(a){return a instanceof SVGElement},dom:function(a){return a.nodeType||g.svg(a)},str:function(a){return"string"===typeof a},fnc:function(a){return"function"===typeof a},und:function(a){return"undefined"===typeof a},hex:function(a){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a)},rgb:function(a){return/^rgb/.test(a)},hsl:function(a){return/^hsl/.test(a)},col:function(a){return g.hex(a)||-g.rgb(a)||g.hsl(a)}},y=function(){function a(a,d,c){return(((1-3*c+3*d)*a+(3*c-6*d))*a+3*d)*a}return function(b,d,c,e){if(0<=b&&1>=b&&0<=c&&1>=c){var g=new Float32Array(11);if(b!==d||c!==e)for(var h=0;11>h;++h)g[h]=a(.1*h,b,c);return function(h){if(b===d&&c===e)return h;if(0===h)return 0;if(1===h)return 1;for(var m=0,k=1;10!==k&&g[k]<=h;++k)m+=.1;--k;var k=m+(h-g[k])/(g[k+1]-g[k])*.1,l=3*(1-3*c+3*b)*k*k+2*(3*c-6*b)*k+3*b;if(.001<=l){for(m=0;4>m;++m){l=3*(1-3*c+3*b)*k*k+2*(3*c-6*b)*k+3*b;if(0===l)break;-var n=a(k,b,c)-h,k=k-n/l}h=k}else if(0===l)h=k;else{var k=m,m=m+.1,f=0;do n=k+(m-k)/2,l=a(n,b,c)-h,0<l?m=n:k=n;while(1e-7<Math.abs(l)&&10>++f);h=n}return a(h,d,e)}}}}(),N=function(){function a(a,b){return 0===a||1===a?a:-Math.pow(2,10*(a-1))*Math.sin(2*(a-1-b/(2*Math.PI)*Math.asin(1))*Math.PI/b)}var b="Quad Cubic Quart Quint Sine Expo Circ Back Elastic".split(" "),d={In:[[.55,.085,.68,.53],[.55,.055,.675,.19],[.895,.03,.685,.22],[.755,.05,.855,.06],[.47,0,.745,.715],[.95,.05,.795,.035],[.6,.04,.98,-.335],[.6,-.28,.735,.045],a],Out:[[.25,.46,.45,.94],[.215,.61,.355,1],[.165,.84,.44,1],[.23,1,.32,1],[.39,.575,.565,1],[.19,1,.22,1],[.075,.82,.165,1],[.175,.885,.32,1.275],function(b,c){return 1-a(1-b,c)}],InOut:[[.455,.03,.515,.955],[.645,.045,.355,1],[.77,0,.175,1],[.86,0,.07,1],[.445,.05,.55,.95],[1,0,0,1],[.785,.135,.15,.86],[.68,-.55,.265,1.55],function(b,c){return.5>b?a(2*b,c)/2:1-a(-2*b+2,c)/2}]},c={linear:y(.25,.25,.75,.75)},e={},l;for(l in d)e.type=l,d[e.type].forEach(function(a){return function(d,-e){c["ease"+a.type+b[e]]=g.fnc(d)?d:y.apply($jscomp$this,d)}}(e)),e={type:e.type};return c}(),ia={css:function(a,b,d){return a.style[b]=d},attribute:function(a,b,d){return a.setAttribute(b,d)},object:function(a,b,d){return a[b]=d},transform:function(a,b,d,c,e){c[e]||(c[e]=[]);c[e].push(b+"("+d+")")}},q=[],z=0,ja=function(){function a(){z=requestAnimationFrame(b)}function b(b){var c=q.length;if(c){for(var d=0;d<c;)q[d]&&q[d].tick(b),d++;a()}else cancelAnimationFrame(z),z=0}return a}();n.version="2.0.2";-n.speed=1;n.running=q;n.remove=function(a){a=M(a);for(var b=q.length;b--;)for(var d=q[b],c=d.animations,e=c.length;e--;)F(a,c[e].animatable.target)&&(c.splice(e,1),c.length||d.pause())};n.getValue=J;n.path=function(a,b){var d=g.str(a)?v(a)[0]:a,c=b||100;return function(a){return{el:d,property:a,totalLength:d.getTotalLength()*(c/100)}}};n.setDashoffset=function(a){var b=a.getTotalLength();a.setAttribute("stroke-dasharray",b);return b};n.bezier=y;n.easings=N;n.timeline=function(a){var b=n(a);b.pause();-b.duration=0;b.add=function(a){b.children.forEach(function(a){a.began=!0;a.completed=!0});w(a).forEach(function(a){var c=b.duration,d=a.offset;a.autoplay=!1;a.offset=g.und(d)?c:K(d,c);b.seek(a.offset);a=n(a);a.duration>c&&(b.duration=a.duration);a.began=!0;b.children.push(a)});b.reset();b.seek(0);b.autoplay&&b.restart();return b};return b};n.random=function(a,b){return Math.floor(Math.random()*(b-a+1))+a};return n});\ No newline at end of file+/**+ * http://anime-js.com+ * JavaScript animation engine+ * @version v2.0.2+ * @author Julian Garnier+ * @copyright ©2017 Julian Garnier+ * Released under the MIT license+**/++(function(root, factory) {+ if (typeof define === 'function' && define.amd) {+ // AMD. Register as an anonymous module.+ define([], factory);+ } else if (typeof module === 'object' && module.exports) {+ // Node. Does not work with strict CommonJS, but+ // only CommonJS-like environments that support module.exports,+ // like Node.+ module.exports = factory();+ } else {+ // Browser globals (root is window)+ root.anime = factory();+ }+}(this, () => {++ // Defaults++ const defaultInstanceSettings = {+ update: undefined,+ begin: undefined,+ run: undefined,+ complete: undefined,+ loop: 1,+ direction: 'normal',+ autoplay: true,+ offset: 0+ }++ const defaultTweenSettings = {+ duration: 1000,+ delay: 0,+ easing: 'easeOutElastic',+ elasticity: 500,+ round: 0+ }++ const validTransforms = ['translateX', 'translateY', 'translateZ', 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scaleX', 'scaleY', 'scaleZ', 'skewX', 'skewY'];+ let transformString;++ // Utils++ function stringContains(str, text) {+ return str.indexOf(text) > -1;+ }++ const is = {+ arr: a => Array.isArray(a),+ obj: a => stringContains(Object.prototype.toString.call(a), 'Object'),+ svg: a => a instanceof SVGElement,+ dom: a => a.nodeType || is.svg(a),+ str: a => typeof a === 'string',+ fnc: a => typeof a === 'function',+ und: a => typeof a === 'undefined',+ hex: a => /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a),+ rgb: a => /^rgb/.test(a),+ hsl: a => /^hsl/.test(a),+ col: a => (is.hex(a) || is.rgb(a) || is.hsl(a))+ }++ // BezierEasing https://github.com/gre/bezier-easing++ const bezier = (() => {++ const kSplineTableSize = 11;+ const kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);++ function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1 };+ function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1 };+ function C (aA1) { return 3.0 * aA1 };++ function calcBezier (aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT };+ function getSlope (aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1) };++ function binarySubdivide (aX, aA, aB, mX1, mX2) {+ let currentX, currentT, i = 0;+ do {+ currentT = aA + (aB - aA) / 2.0;+ currentX = calcBezier(currentT, mX1, mX2) - aX;+ if (currentX > 0.0) { aB = currentT } else { aA = currentT };+ } while (Math.abs(currentX) > 0.0000001 && ++i < 10);+ return currentT;+ }++ function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) {+ for (let i = 0; i < 4; ++i) {+ const currentSlope = getSlope(aGuessT, mX1, mX2);+ if (currentSlope === 0.0) return aGuessT;+ const currentX = calcBezier(aGuessT, mX1, mX2) - aX;+ aGuessT -= currentX / currentSlope;+ }+ return aGuessT;+ }++ function bezier(mX1, mY1, mX2, mY2) {++ if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) return;+ let sampleValues = new Float32Array(kSplineTableSize);++ if (mX1 !== mY1 || mX2 !== mY2) {+ for (let i = 0; i < kSplineTableSize; ++i) {+ sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);+ }+ }++ function getTForX(aX) {++ let intervalStart = 0.0;+ let currentSample = 1;+ const lastSample = kSplineTableSize - 1;++ for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) {+ intervalStart += kSampleStepSize;+ }++ --currentSample;++ const dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);+ const guessForT = intervalStart + dist * kSampleStepSize;+ const initialSlope = getSlope(guessForT, mX1, mX2);++ if (initialSlope >= 0.001) {+ return newtonRaphsonIterate(aX, guessForT, mX1, mX2);+ } else if (initialSlope === 0.0) {+ return guessForT;+ } else {+ return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);+ }++ }++ return x => {+ if (mX1 === mY1 && mX2 === mY2) return x;+ if (x === 0) return 0;+ if (x === 1) return 1;+ return calcBezier(getTForX(x), mY1, mY2);+ }++ }++ return bezier;++ })();++ const easings = (() => {++ const names = ['Quad', 'Cubic', 'Quart', 'Quint', 'Sine', 'Expo', 'Circ', 'Back', 'Elastic'];++ // Elastic easing adapted from jQueryUI http://api.jqueryui.com/easings/++ function elastic(t, p) {+ return t === 0 || t === 1 ? t :+ -Math.pow(2, 10 * (t - 1)) * Math.sin((((t - 1) - (p / (Math.PI * 2.0) * Math.asin(1))) * (Math.PI * 2)) / p );+ }++ // Approximated Penner equations http://matthewlein.com/ceaser/++ const equations = {+ In: [+ [0.550, 0.085, 0.680, 0.530], /* InQuad */+ [0.550, 0.055, 0.675, 0.190], /* InCubic */+ [0.895, 0.030, 0.685, 0.220], /* InQuart */+ [0.755, 0.050, 0.855, 0.060], /* InQuint */+ [0.470, 0.000, 0.745, 0.715], /* InSine */+ [0.950, 0.050, 0.795, 0.035], /* InExpo */+ [0.600, 0.040, 0.980, 0.335], /* InCirc */+ [0.600, -0.280, 0.735, 0.045], /* InBack */+ elastic /* InElastic */+ ], Out: [+ [0.250, 0.460, 0.450, 0.940], /* OutQuad */+ [0.215, 0.610, 0.355, 1.000], /* OutCubic */+ [0.165, 0.840, 0.440, 1.000], /* OutQuart */+ [0.230, 1.000, 0.320, 1.000], /* OutQuint */+ [0.390, 0.575, 0.565, 1.000], /* OutSine */+ [0.190, 1.000, 0.220, 1.000], /* OutExpo */+ [0.075, 0.820, 0.165, 1.000], /* OutCirc */+ [0.175, 0.885, 0.320, 1.275], /* OutBack */+ (t, f) => 1 - elastic(1 - t, f) /* OutElastic */+ ], InOut: [+ [0.455, 0.030, 0.515, 0.955], /* InOutQuad */+ [0.645, 0.045, 0.355, 1.000], /* InOutCubic */+ [0.770, 0.000, 0.175, 1.000], /* InOutQuart */+ [0.860, 0.000, 0.070, 1.000], /* InOutQuint */+ [0.445, 0.050, 0.550, 0.950], /* InOutSine */+ [1.000, 0.000, 0.000, 1.000], /* InOutExpo */+ [0.785, 0.135, 0.150, 0.860], /* InOutCirc */+ [0.680, -0.550, 0.265, 1.550], /* InOutBack */+ (t, f) => t < .5 ? elastic(t * 2, f) / 2 : 1 - elastic(t * -2 + 2, f) / 2 /* InOutElastic */+ ]+ }++ let functions = {+ linear: bezier(0.250, 0.250, 0.750, 0.750)+ }++ for (let type in equations) {+ equations[type].forEach((f, i) => {+ functions['ease'+type+names[i]] = is.fnc(f) ? f : bezier.apply(this, f);+ });+ }++ return functions;++ })();++ // Strings++ function stringToHyphens(str) {+ return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();+ }++ function selectString(str) {+ if (is.col(str)) return;+ try {+ let nodes = document.querySelectorAll(str);+ return nodes;+ } catch(e) {+ return;+ }+ }++ // Arrays++ function arrayLength(arr) {+ return arr.length;+ }++ function flattenArray(arr) {+ return arr.reduce((a, b) => a.concat(is.arr(b) ? flattenArray(b) : b), []);+ }++ function toArray(o) {+ if (is.arr(o)) return o;+ if (is.str(o)) o = selectString(o) || o;+ if (o instanceof NodeList || o instanceof HTMLCollection) return [].slice.call(o);+ return [o];+ }++ // Objects++ function objectHas(obj, prop) {+ return obj.hasOwnProperty(prop);+ }++ function cloneObject(o) {+ let clone = {};+ for (let p in o) clone[p] = o[p];+ return clone;+ }++ function replaceObjectProps(o1, o2) {+ let o = cloneObject(o1);+ for (let p in o1) o[p] = objectHas(o2, p) ? o2[p] : o1[p];+ return o;+ }++ function mergeObjects(o1, o2) {+ let o = cloneObject(o1);+ for (let p in o2) o[p] = is.und(o1[p]) ? o2[p] : o1[p];+ return o;+ }++ // Colors++ function hexToRgb(hexValue) {+ const rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;+ const hex = hexValue.replace(rgx, (m, r, g, b) => r + r + g + g + b + b );+ const rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);+ const r = parseInt(rgb[1], 16);+ const g = parseInt(rgb[2], 16);+ const b = parseInt(rgb[3], 16);+ return `rgb(${r},${g},${b})`;+ }++ function hslToRgb(hslValue) {+ const hsl = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(hslValue);+ const h = parseInt(hsl[1]) / 360;+ const s = parseInt(hsl[2]) / 100;+ const l = parseInt(hsl[3]) / 100;+ function hue2rgb(p, q, t) {+ if (t < 0) t += 1;+ if (t > 1) t -= 1;+ if (t < 1/6) return p + (q - p) * 6 * t;+ if (t < 1/2) return q;+ if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;+ return p;+ }+ let r, g, b;+ if (s == 0) {+ r = g = b = l;+ } else {+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;+ const p = 2 * l - q;+ r = hue2rgb(p, q, h + 1/3);+ g = hue2rgb(p, q, h);+ b = hue2rgb(p, q, h - 1/3);+ }+ return `rgb(${r * 255},${g * 255},${b * 255})`;+ }++ function colorToRgb(val) {+ if (is.rgb(val)) return val;+ if (is.hex(val)) return hexToRgb(val);+ if (is.hsl(val)) return hslToRgb(val);+ }++ // Units++ function getUnit(val) {+ const split = /([\+\-]?[0-9#\.]+)(%|px|pt|em|rem|in|cm|mm|ex|pc|vw|vh|deg|rad|turn)?/.exec(val);+ if (split) return split[2];+ // if (split && split[2] && val.indexOf(split[2], arrayLength(val) - arrayLength(split[2])) !== -1) return split[2];+ }++ function getTransformUnit(propName) {+ if (stringContains(propName, 'translate')) return 'px';+ if (stringContains(propName, 'rotate') || stringContains(propName, 'skew')) return 'deg';+ }++ // Values++ function parseFloatValue(val) {+ return parseFloat(val);+ }++ function minMaxValue(val, min, max) {+ return Math.min(Math.max(val, min), max);+ }++ function getFunctionValue(val, animatable) {+ if (!is.fnc(val)) return val;+ return val(animatable.target, animatable.id, animatable.total);+ }++ function getCSSValue(el, prop) {+ if (prop in el.style) {+ return getComputedStyle(el).getPropertyValue(stringToHyphens(prop)) || '0';+ }+ }++ function getAnimationType(el, prop) {+ const isDom = is.dom(el);+ if (isDom && validTransforms.some(a => a === prop)) return 'transform';+ if (isDom && (el.getAttribute(prop) || (is.svg(el) && el[prop]))) return 'attribute';+ if (isDom && (prop !== 'transform' && (prop in el.style))) return 'css';+ if (el[prop] != null) return 'object';+ }++ function getTransformValue(el, propName) {+ const defaultUnit = getTransformUnit(propName);+ const defaultVal = stringContains(propName, 'scale') ? 1 : 0 + defaultUnit;+ const str = el.style.transform;+ if (!str) return defaultVal;+ let match = [];+ let props = [];+ let values = [];+ const rgx = /(\w+)\((.+?)\)/g;+ while (match = rgx.exec(str)) {+ props.push(match[1]);+ values.push(match[2]);+ }+ const value = values.filter((val, i) => props[i] === propName );+ return arrayLength(value) ? value[0] : defaultVal;+ }++ function getOriginalTargetValue(target, propName) {+ switch (getAnimationType(target, propName)) {+ case 'transform': return getTransformValue(target, propName);+ case 'css': return getCSSValue(target, propName);+ case 'attribute': return target.getAttribute(propName);+ }+ return target[propName] || 0;+ }++ function getRelativeValue(to, from) {+ const operator = /^(\*=|\+=|-=)/.exec(to);+ if (!operator) return to;+ const x = parseFloatValue(from);+ const y = parseFloatValue(to.replace(operator[0], ''));+ switch (operator[0][0]) {+ case '+': return x + y;+ case '-': return x - y;+ case '*': return x * y;+ }+ }++ function validateValue(val, unit) {+ if (is.col(val)) return colorToRgb(val);+ return unit && !isNaN(val) ? val + unit : val;+ }++ // Motion path++ function isPath(val) {+ return is.obj(val) && objectHas(val, 'totalLength');+ }++ function setDashoffset(el) {+ const pathLength = el.getTotalLength();+ el.setAttribute('stroke-dasharray', pathLength);+ return pathLength;+ }++ function getPath(path, percent) {+ const el = is.str(path) ? selectString(path)[0] : path;+ const p = percent || 100;+ return function(prop) {+ return {+ el: el,+ property: prop,+ totalLength: el.getTotalLength() * (p / 100)+ }+ }+ }++ function getPathProgress(path, progress) {+ function point(offset = 0) {+ const l = progress + offset >= 1 ? progress + offset : 0;+ return path.el.getPointAtLength(l);+ }+ const p = point();+ const p0 = point(-1);+ const p1 = point(+1);+ switch (path.property) {+ case 'x': return p.x;+ case 'y': return p.y;+ case 'angle': return Math.atan2(p1.y - p0.y, p1.x - p0.x) * 180 / Math.PI;+ }+ }++ // Decompose / recompose functions adapted from Animate Plus https://github.com/bendc/animateplus++ function decomposeValue(val, unit) {+ const rgx = /-?\d*\.?\d+/g;+ const value = validateValue((isPath(val) ? val.totalLength : val), unit);+ return {+ original: value,+ numbers: !is.str(value) ? [value] : value.match(rgx) ? value.match(rgx).map(Number) : [0],+ strings: is.str(value) ? value.split(rgx) : [0, 0]+ }+ }++ function recomposeValue(numbers, strings) {+ return strings.reduce((a, b, i) => a + numbers[i - 1] + b);+ }++ // Animatables++ function parseTargets(targets) {+ const targetsArray = targets ? (flattenArray(is.arr(targets) ? targets.map(toArray) : toArray(targets))) : [];+ return targetsArray.filter((item, pos, self) => self.indexOf(item) === pos);+ }++ function getAnimatables(targets) {+ const parsed = parseTargets(targets);+ return parsed.map((t, i) => {+ return {target: t, id: i, total: arrayLength(parsed)};+ });+ }++ // Properties++ function normalizePropertyTweens(prop, tweenSettings) {+ let settings = cloneObject(tweenSettings);+ if (is.arr(prop)) {+ const l = arrayLength(prop);+ const isFromTo = (l === 2 && !is.obj(prop[0]));+ if (!isFromTo) {+ // Duration divided by the number of tweens+ if (!is.fnc(tweenSettings.duration)) settings.duration = tweenSettings.duration / l;+ } else {+ // Transform [from, to] values shorthand to a valid tween value+ prop = {value: prop};+ }+ }+ return toArray(prop).map((v, i) => {+ // Default delay value should be applied only on the first tween+ const delay = !i ? tweenSettings.delay : 0;+ // Use path object as a tween value+ let obj = is.obj(v) && !isPath(v) ? v : {value: v};+ // Set default delay value+ if (is.und(obj.delay)) obj.delay = delay;+ return obj;+ }).map(k => mergeObjects(k, settings));+ }++ function getProperties(instanceSettings, tweenSettings, params) {+ let properties = [];+ const settings = mergeObjects(instanceSettings, tweenSettings);+ for (let p in params) {+ if (!objectHas(settings, p) && p !== 'targets') {+ properties.push({+ name: p,+ offset: settings['offset'],+ tweens: normalizePropertyTweens(params[p], tweenSettings)+ });+ }+ }+ return properties;+ }++ // Tweens++ function normalizeTweenValues(tween, animatable) {+ let t = {};+ for (let p in tween) {+ let value = getFunctionValue(tween[p], animatable);+ if (is.arr(value)) {+ value = value.map(v => getFunctionValue(v, animatable));+ if (arrayLength(value) === 1) value = value[0];+ }+ t[p] = value;+ }+ t.duration = parseFloatValue(t.duration);+ t.delay = parseFloatValue(t.delay);+ return t;+ }++ function normalizeEasing(val) {+ return is.arr(val) ? bezier.apply(this, val) : easings[val];+ }++ function normalizeTweens(prop, animatable) {+ let previousTween;+ return prop.tweens.map(t => {+ let tween = normalizeTweenValues(t, animatable);+ const tweenValue = tween.value;+ const originalValue = getOriginalTargetValue(animatable.target, prop.name);+ const previousValue = previousTween ? previousTween.to.original : originalValue;+ const from = is.arr(tweenValue) ? tweenValue[0] : previousValue;+ const to = getRelativeValue(is.arr(tweenValue) ? tweenValue[1] : tweenValue, from);+ const unit = getUnit(to) || getUnit(from) || getUnit(originalValue);+ tween.isPath = isPath(tweenValue);+ tween.from = decomposeValue(from, unit);+ tween.to = decomposeValue(to, unit);+ tween.start = previousTween ? previousTween.end : prop.offset;+ tween.end = tween.start + tween.delay + tween.duration;+ tween.easing = normalizeEasing(tween.easing);+ tween.elasticity = (1000 - minMaxValue(tween.elasticity, 1, 999)) / 1000;+ if (is.col(tween.from.original)) tween.round = 1;+ previousTween = tween;+ return tween;+ });+ }++ // Tween progress++ const setTweenProgress = {+ css: (t, p, v) => t.style[p] = v,+ attribute: (t, p, v) => t.setAttribute(p, v),+ object: (t, p, v) => t[p] = v,+ transform: (t, p, v, transforms, id) => {+ if (!transforms[id]) transforms[id] = [];+ transforms[id].push(`${p}(${v})`);+ }+ }++ // Animations++ function createAnimation(animatable, prop) {+ const animType = getAnimationType(animatable.target, prop.name);+ if (animType) {+ const tweens = normalizeTweens(prop, animatable);+ return {+ type: animType,+ property: prop.name,+ animatable: animatable,+ tweens: tweens,+ duration: tweens[arrayLength(tweens) - 1].end,+ delay: tweens[0].delay+ }+ }+ }++ function getAnimations(animatables, properties) {+ return flattenArray(animatables.map(animatable => {+ return properties.map(prop => {+ return createAnimation(animatable, prop);+ });+ })).filter(a => !is.und(a));+ }++ // Create Instance++ 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];+ }++ function createNewInstance(params) {+ const instanceSettings = replaceObjectProps(defaultInstanceSettings, params);+ const tweenSettings = replaceObjectProps(defaultTweenSettings, params);+ const animatables = getAnimatables(params.targets);+ const properties = getProperties(instanceSettings, tweenSettings, params);+ const animations = getAnimations(animatables, properties);+ return mergeObjects(instanceSettings, {+ animatables: animatables,+ animations: animations,+ duration: getInstanceTimings('duration', animations, tweenSettings),+ delay: getInstanceTimings('delay', animations, tweenSettings)+ });+ }++ // Core++ let activeInstances = [];+ let raf = 0;++ const engine = (() => {+ function play() { raf = requestAnimationFrame(step); };+ function step(t) {+ const activeLength = arrayLength(activeInstances);+ if (activeLength) {+ let i = 0;+ while (i < activeLength) {+ if (activeInstances[i]) activeInstances[i].tick(t);+ i++;+ }+ play();+ } else {+ cancelAnimationFrame(raf);+ raf = 0;+ }+ }+ return play;+ })();+++ // Public Instance++ function anime(params = {}) {++ let now, startTime, lastTime = 0;++ let resolve = null;++ function makePromise() {+ return window.Promise && new Promise(_resolve => resolve = _resolve);+ }++ let promise = makePromise();++ let instance = createNewInstance(params);++ instance.reset = function() {+ const direction = instance.direction;+ const loops = instance.loop;+ instance.currentTime = 0;+ instance.progress = 0;+ instance.paused = true;+ instance.began = false;+ instance.completed = false;+ instance.reversed = direction === 'reverse';+ instance.remaining = direction === 'alternate' && loops === 1 ? 2 : loops;+ }++ function toggleInstanceDirection() {+ instance.reversed = !instance.reversed;+ }++ function adjustTime(time) {+ return instance.reversed ? instance.duration - time : time;+ }++ function syncInstanceChildren(insTime) {+ let i = 0;+ const children = instance.children;+ while (i < arrayLength(children)) {+ children[i].seek(insTime);+ i++;+ }+ }++ function setAnimationsProgress(insTime) {+ let i = 0;+ let transforms = {};+ const animations = instance.animations;+ while (i < arrayLength(animations)) {+ const anim = animations[i];+ const animatable = anim.animatable;+ const tweens = anim.tweens;+ const tween = tweens.filter(t => (insTime < t.end))[0] || tweens[arrayLength(tweens) - 1];+ const isPath = tween.isPath;+ const round = tween.round;+ const elapsed = minMaxValue(insTime - tween.start - tween.delay, 0, tween.duration) / tween.duration;+ const eased = tween.easing(elapsed, tween.elasticity);+ const progress = recomposeValue(tween.to.numbers.map((number, p) => {+ const start = isPath ? 0 : tween.from.numbers[p];+ let value = start + eased * (number - start);+ if (isPath) value = getPathProgress(tween.value, value);+ if (round) value = Math.round(value * round) / round;+ return value;+ }), tween.to.strings);+ setTweenProgress[anim.type](animatable.target, anim.property, progress, transforms, animatable.id);+ anim.currentValue = progress;+ i++;+ }+ if (transforms) {+ let id; for (id in transforms) {+ if (!transformString) {+ const t = 'transform';+ transformString = (getCSSValue(document.body, t) ? t : `-webkit-${t}`);+ }+ instance.animatables[id].target.style[transformString] = transforms[id].join(' ');+ }+ }+ instance.currentTime = insTime;+ instance.progress = (insTime / instance.duration) * 100;+ }++ function setCallback(cb) {+ if (instance[cb]) instance[cb](instance);+ }++ function setInstanceProgress(engineTime) {+ const insDuration = instance.duration;+ const insOffset = instance.offset;+ const insDelay = instance.delay;+ const insCurrentTime = instance.currentTime;+ const insRemaining = instance.remaining;+ const insReversed = instance.reversed;+ const insTime = minMaxValue(adjustTime(engineTime), 0, insDuration);+ if (insTime >= insOffset && insTime <= insDuration) {+ setAnimationsProgress(insTime);+ if (!instance.began && insTime >= insDelay) {+ instance.began = true;+ setCallback('begin');+ }+ setCallback('run');+ }+ if (insRemaining && insRemaining !== true) {+ if (+ (insReversed && insTime === insOffset && insCurrentTime !== 0) ||+ (!insReversed && insTime === insDuration && insCurrentTime !== insDuration)) {+ instance.remaining--;+ }+ }+ if (engineTime >= insDuration) {+ if (instance.remaining) {+ startTime = now;+ if (instance.direction === 'alternate') toggleInstanceDirection();+ } else {+ instance.pause();+ resolve();+ promise = makePromise();+ if (!instance.completed) {+ instance.completed = true;+ setCallback('complete');+ }+ }+ lastTime = 0;+ }+ if (instance.children) syncInstanceChildren(insTime);+ setCallback('update');+ }++ instance.tick = function(t) {+ now = t;+ if (!startTime) startTime = now;+ const engineTime = (lastTime + now - startTime) * anime.speed;+ setInstanceProgress(engineTime);+ }++ instance.seek = function(time) {+ setInstanceProgress(adjustTime(time));+ }++ instance.pause = function() {+ const i = activeInstances.indexOf(instance);+ if (i > -1) activeInstances.splice(i, 1);+ instance.paused = true;+ }++ instance.play = function() {+ if (!instance.paused) return;+ instance.paused = false;+ startTime = 0;+ lastTime = instance.completed ? 0 : adjustTime(instance.currentTime);+ activeInstances.push(instance);+ if (!raf) engine();+ }++ instance.reverse = function() {+ toggleInstanceDirection();+ startTime = 0;+ lastTime = adjustTime(instance.currentTime);+ }++ instance.restart = function() {+ instance.pause();+ instance.reset();+ instance.play();+ }++ instance.finished = promise;++ instance.reset();++ if (instance.autoplay) instance.play();++ return instance;++ }++ // Remove targets from animation++ function removeTargets(targets) {+ const targetsArray = parseTargets(targets);+ for (let i = arrayLength(activeInstances)-1; i >= 0; i--) {+ const instance = activeInstances[i];+ const animations = instance.animations;+ for (let a = arrayLength(animations)-1; a >= 0; a--) {+ if (targetsArray.some(t => t === animations[a].animatable.target)) {+ animations.splice(a, 1);+ if (!arrayLength(animations)) instance.pause();+ }+ }+ }+ }++ // Timeline++ function timeline(params) {+ let tl = anime(params);+ tl.duration = 0;+ tl.children = [];+ tl.add = function(instancesParams) {+ tl.children.forEach( i => { i.began = true; i.completed = true; });+ toArray(instancesParams).forEach(insParams => {+ const tlDuration = tl.duration;+ const insOffset = insParams.offset;+ insParams.autoplay = false;+ insParams.offset = is.und(insOffset) ? tlDuration : getRelativeValue(insOffset, tlDuration);+ tl.seek(insParams.offset);+ const ins = anime(insParams);+ if (ins.duration > tlDuration) tl.duration = ins.duration;+ ins.began = true;+ tl.children.push(ins);+ });+ tl.seek(0);+ tl.reset();+ for (let i = tl.children.length; i--; ){+ const child = tl.children[i];+ child.seek(child.offset);+ child.reset();+ }+ if (tl.autoplay) tl.play();+ return tl;+ }+ return tl;+ }++ anime.version = '2.0.2';+ anime.speed = 1;+ anime.running = activeInstances;+ anime.remove = removeTargets;+ anime.getValue = getOriginalTargetValue;+ anime.path = getPath;+ anime.setDashoffset = setDashoffset;+ anime.bezier = bezier;+ anime.easings = easings;+ anime.timeline = timeline;+ anime.random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;++ return anime;++}));\ No newline at end of filediff --git a/documentation/examples/anime-DOM-stress-test.html b/documentation/examples/anime-DOM-stress-test.htmlindex 3b400f12..2883b81b 100644--- a/documentation/examples/anime-DOM-stress-test.html+++ b/documentation/examples/anime-DOM-stress-test.html@@ -40,7 +40,7 @@<body></body><script>- var maxElements = Number(location.href.split('?')[1]) || 500;+ var maxElements = Number(location.href.split('?')[1]) || 1000;var duration = 2000;var toAnimate = [];var radius = window.innerWidth < window.innerHeight ? window.innerWidth : window.innerHeight;@@ -68,7 +68,7 @@var angle = i * 4;// var delay = ((duration * 2) / maxElements) * i;// var angle = i * 1000;- var delay = (duration / maxElements) * i * 10;+ var delay = (duration / maxElements) * i * 1;var a = anime({targets: el,translateX: [0, Math.sin(angle) * distance],diff --git a/documentation/examples/anime-speed-test.html b/documentation/examples/anime-speed-test.htmlindex e61f95fb..2e3cb446 100644--- a/documentation/examples/anime-speed-test.html+++ b/documentation/examples/anime-speed-test.html@@ -27,36 +27,47 @@}.particule {position: absolute;- width: 4px;- height: 4px;- margin: -2px 0 0 -2px;+ width: 10px;+ height: 10px;+ margin: -5px 0 0 -5px;border-radius: 50%;- background-color: #FBF38C;+ /*background-color: #FBF38C;*/+ background-color: currentColor;}</style></head><body><script>- var maxElements = 600;- var duration = 1000;+ var maxElements = 500;+ var duration = 2000;var width = window.innerWidth;var height = window.innerHeight;- var distance = (width > height ? height : width) / 2.75;+ var distance = (width > height ? height : width) / 4;var fragment = document.createDocumentFragment();+ var colors = ['#FF1461', '#18FF92', '#5A87FF'];var i = 0;while (i <= maxElements) {var angle = Math.random() * Math.PI * 2;var el = document.createElement('div');+ var color = Math.round((i/maxElements)*(colors.length-1));+ // el.style.color = colors[anime.random(0, 3)];+ // el.style.color = colors[color];el.classList.add('particule');anime({targets: el,left: [width/2+'px', Math.cos(angle) * distance + (width/2) + 'px'],top: [height/2+'px', Math.sin(angle) * distance + (height/2) + 'px'],+ // scale: [+ // {value: [.5, 1.5], duration: duration * .8},+ // {value: 1.5, duration: duration * .1},+ // {value: 0, duration: duration * .1}+ // ],+ color: ['#FF1461', '#5A87FF'],delay: (duration / maxElements) * i,duration: duration,- direction: 'reverse',+ // direction: 'reverse',easing: 'easeOutSine',loop: true});diff --git a/documentation/examples/anime-staggered-animations.html b/documentation/examples/anime-staggered-animations.htmlindex 48324959..58fa2a0d 100644--- a/documentation/examples/anime-staggered-animations.html+++ b/documentation/examples/anime-staggered-animations.html@@ -61,38 +61,52 @@return Math.pow(Math.sin(t * 3), 3);}+ var tl = anime.timeline({+ loop: true,+ update: function() {+ // console.log('upd');+ }+ });+function createEl(i) {let el = {};el.node = document.createElement('div');el.node.classList.add('el');el.node.style.backgroundColor = 'hsl('+ Math.round(360 / numberOfEls * i) +', 40%, 60%)';el.node.style.transform = 'rotate('+ 180 + (360 / numberOfEls) * i +'deg) translateY(-50%)';- el.animation = anime({- targets: el.node,- rotate: [- {value: '+=10', duration: duration * .1},- {value: '-=10', duration: duration * .1, easing: 'easeInOutQuad'},- {value: '+=0', duration: duration * .8}- ],- translateY: [- {value: '+=10', duration: duration * .1},- {value: '-=10', duration: duration * .1, easing: 'easeInOutQuad'},- {value: '+=0', duration: duration * .8}- ],- scale: [- {value: 1.2, duration: duration * .1},- {value: 1, duration: duration * .1, easing: 'easeInOutQuad'},- {value: 1, duration: duration * .8}- ],- easing: 'easeInOutQuad',- duration: duration,- delay: delay * i,- loop: true,- direction: 'staggered'+ tl.add({+ complete: function() {+ console.log('complete');+ anime({+ targets: el.node,+ rotate: [+ {value: '+=10', duration: duration * .1},+ {value: '-=10', duration: duration * .1, easing: 'easeInOutQuad'},+ {value: '+=0', duration: duration * .8}+ ],+ translateY: [+ {value: '+=10', duration: duration * .1},+ {value: '-=10', duration: duration * .1, easing: 'easeInOutQuad'},+ {value: '+=0', duration: duration * .8}+ ],+ scale: [+ {value: 1.2, duration: duration * .1},+ {value: 1, duration: duration * .1, easing: 'easeInOutQuad'},+ {value: 1, duration: duration * .8}+ ],+ easing: 'easeInOutQuad',+ duration: duration,+ });+ },+ duration: 0,+ offset: delay * i,});+ console.log(delay * i);wrapperEl.appendChild(el.node);els.push(el);- }+ };++ console.log(tl);for (let i = 0; i < numberOfEls; i++) createEl(i);@@ -104,7 +118,7 @@// }// }- document.addEventListener('visibilitychange', handleVisibilityChange, false);+ // document.addEventListener('visibilitychange', handleVisibilityChange, false);</script><script src="../assets/js/stats.js"></script>diff --git a/documentation/examples/anime-staggered-timeline-animations.html b/documentation/examples/anime-staggered-timeline-animations.htmlnew file mode 100644index 00000000..4d3e7cb5--- /dev/null+++ b/documentation/examples/anime-staggered-timeline-animations.html@@ -0,0 +1,104 @@+<!DOCTYPE html>+<html>+<head>+ <title>Staggered loops | anime.js</title>+ <meta charset="utf-8">+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">+ <meta property="og:title" content="anime.js">+ <meta property="og:url" content="http://animejs.com">+ <meta property="og:description" content="Javascript Animation Engine">+ <meta property="og:image" content="http://animejs.com/documentation/assets/img/icons/og.png">+ <meta name="twitter:card" content="summary">+ <meta name="twitter:title" content="anime.js">+ <meta name="twitter:site" content="@juliangarnier">+ <meta name="twitter:description" content="Javascript Animation Engine">+ <meta name="twitter:image" content="http://animejs.com/documentation/assets/img/icons/twitter.png">+ <link rel="apple-touch-icon-precomposed" href="../assets/img/icons/apple-touch-icon.png">+ <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.1.3.js"></script> -->+ <style>+ body {+ display: flex;+ justify-content: center;+ align-items: center;+ width: 100%;+ height: 100vh;+ }++ .wrapper {+ position: relative;+ display: flex;+ flex-direction: column;+ flex-wrap: wrap;+ width: 1px;+ height: 80vh;+ }++ .el {+ margin: 0 20px;+ opacity: 1;+ width: 2px;+ height: 30%;+ transform-origin: 0% 100%;+ background: white;+ }+ </style>+</head>+<body>+ <div class="el el-01"></div>+ <div class="el el-02"></div>+ <div class="el el-03"></div>+ <div class="el el-04"></div>+ <div class="el el-05"></div>+ <script>++ var tl = anime.timeline({+ duration: 100,+ easing: 'linear',+ complete: function() { tl.restart(); }+ });++ tl.add({+ begin: function() {+ anime({+ targets: '.el-01',+ translateY: [0, 50]+ });+ },+ }).add({+ begin: function() {+ anime({+ targets: '.el-02',+ translateY: [0, 50]+ });+ },+ }).add({+ begin: function() {+ anime({+ targets: '.el-03',+ translateY: [0, 50]+ });+ },+ }).add({+ begin: function() {+ anime({+ targets: '.el-04',+ translateY: [0, 50]+ });+ },+ }).add({+ begin: function() {+ anime({+ targets: '.el-05',+ translateY: [0, 50]+ });+ },+ })++ </script>+ <script src="../assets/js/stats.js"></script>+</body>+</html>diff --git a/documentation/examples/anime-tests.html b/documentation/examples/anime-tests.htmlindex d51f8e37..ecbcf7a9 100644--- a/documentation/examples/anime-tests.html+++ b/documentation/examples/anime-tests.html@@ -41,27 +41,27 @@<div class="el color-08"></div><div class="el color-12"></div><script>- var seek0 = anime({- targets: '.color-01',- translateY: [300, 100],- // loop: true,- autoplay: false,- update: function(anim) { console.log('update', anim.currentTime);},- begin: function(anim) { console.log('begin', anim.currentTime);},- run: function(anim) { console.log('run', anim.currentTime);},- complete: function(anim) { console.log('complete', anim.currentTime);}- });- var duration0 = anime({- targets: '.color-04',- translateY: [200, 300],- loop: true,- autoplay: false,- duration: 0,- update: function() { console.log('update');},- begin: function() { console.log('begin');},- run: function() { console.log('run');},- complete: function() { console.log('complete');}- });+ // var seek0 = anime({+ // targets: '.color-01',+ // translateY: [300, 100],+ // // loop: true,+ // autoplay: false,+ // update: function(anim) { console.log('update', anim.currentTime);},+ // begin: function(anim) { console.log('begin', anim.currentTime);},+ // run: function(anim) { console.log('run', anim.currentTime);},+ // complete: function(anim) { console.log('complete', anim.currentTime);}+ // });+ // var duration0 = anime({+ // targets: '.color-04',+ // translateY: [200, 300],+ // loop: true,+ // autoplay: false,+ // duration: 0,+ // update: function() { console.log('update');},+ // begin: function() { console.log('begin');},+ // run: function() { console.log('run');},+ // complete: function() { console.log('complete');}+ // });// console.log(duration0.currentTime);// animation.seek(0);// console.log(animation.currentTime);@@ -70,6 +70,7 @@autoplay: true,easing: 'easeOutExpo',duration: 500,+ autoplay: false,// update: function(anim) { console.log('TL update', anim.currentTime);},begin: function(anim) { console.log('TL begin', anim.currentTime);},// run: function(anim) { console.log('TL run', anim.currentTime);},@@ -77,18 +78,49 @@});tl.add({- translateY: [-100, 200]+ translateY: [-100, 200],+ begin: function() {+ console.log('01 begin');+ },+ complete: function() {+ console.log('01 complete');+ }}).add({translateY: 0,- easing: 'easeOutElastic'+ easing: 'easeOutElastic',+ begin: function() {+ console.log('02 begin');+ },+ complete: function() {+ console.log('02 complete');+ }}).add({targets: '.color-12',translateY: [0, 100],- easing: 'easeInElastic'+ easing: 'easeInElastic',+ begin: function() {+ console.log('03 begin');+ },+ complete: function() {+ console.log('03 complete');+ },+ offset: 0}).add({- translateY: 100+ translateY: 100,+ begin: function() {+ console.log('04 begin');+ },+ complete: function() {+ console.log('04 complete');+ }}).add({- translateY: 0+ translateY: 0,+ begin: function() {+ console.log('05 begin');+ },+ complete: function() {+ console.log('05 complete');+ }})var promise = tl.finished.then(function() {