Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Reverte easing syntax / cleanup code

Julian Garnier156787bc707c
diff --git a/anime.js b/anime.js
index 60b8df7c..b39b2240 100644
--- a/anime.js
+++ b/anime.js
@@ -40,7 +40,7 @@
duration: 1000,
delay: 0,
endDelay: 0,
- easing: 'outQuad',
+ easing: 'easeOutQuad',
round: 0
}
@@ -228,7 +228,7 @@
// Approximated Penner equations http://matthewlein.com/ceaser/
const penner = {
- in: [
+ 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 */
@@ -238,7 +238,8 @@
[0.600, 0.040, 0.980, 0.335], /* inCirc */
[0.600,-0.280, 0.735, 0.045], /* inBack */
elastic /* inElastic */
- ], out: [
+ ],
+ 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 */
@@ -248,7 +249,8 @@
[0.075, 0.820, 0.165, 1.000], /* outCirc */
[0.175, 0.885, 0.320, 1.275], /* outBack */
(a, p) => t => 1 - elastic(a, p)(1 - t) /* outElastic */
- ], inOut: [
+ ],
+ 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 */
@@ -267,7 +269,7 @@
for (let equation in penner) {
penner[equation].forEach((ease, i) => {
- eases[equation+names[i]] = ease;
+ eases['ease'+equation+names[i]] = ease;
});
}
@@ -794,6 +796,7 @@
function anime(params = {}) {
let startTime = 0, lastTime = 0, now = 0;
+ let lastStartTime = 0;
let children, childrenLength = 0;
let resolve = null;
@@ -810,6 +813,11 @@
children.forEach(child => child.reversed = instance.reversed);
}
+ function resetTime() {
+ startTime = 0;
+ lastTime = adjustTime(instance.currentTime);
+ }
+
function adjustTime(time) {
return instance.reversed ? instance.duration - time : time;
}
@@ -915,11 +923,13 @@
}
if ((insTime >= insDuration && instance.currentTime !== insDuration) || !insDuration) {
setAnimationsProgress(insDuration);
+ lastStartTime = startTime;
if (!instance.reversed) countIteration();
}
}
setCallback('update');
if (engineTime >= insDuration) {
+ lastTime = 0;
if (instance.remaining) {
startTime = now;
if (instance.direction === 'alternate') toggleInstanceDirection();
@@ -934,7 +944,6 @@
}
}
}
- lastTime = 0;
}
}
@@ -971,16 +980,14 @@
instance.play = function() {
if (!instance.paused) return;
instance.paused = false;
- startTime = 0;
- lastTime = adjustTime(instance.currentTime);
+ resetTime();
activeInstances.push(instance);
if (!raf) engine();
}
instance.reverse = function() {
toggleInstanceDirection();
- startTime = 0;
- lastTime = adjustTime(instance.currentTime);
+ resetTime();
}
instance.restart = function() {
@@ -993,8 +1000,10 @@
instance.reset();
- const offBy = instance.startTime - (instance.duration * Math.floor(instance.startTime / instance.duration));
- setInstanceProgress(offBy);
+ if (instance.startTime) {
+ setInstanceProgress(instance.startTime - (instance.duration * Math.floor(instance.startTime / instance.duration)));
+ }
+
if (instance.autoplay) instance.play();
return instance;
diff --git a/documentation/examples/anime-infinite-animation.html b/documentation/examples/anime-infinite-animation.html
index 2677a8d8..6ede9d68 100644
--- a/documentation/examples/anime-infinite-animation.html
+++ b/documentation/examples/anime-infinite-animation.html
@@ -30,12 +30,11 @@
display: flex;
justify-content: center;
align-items: center;
- font-size: 24px;
+ font-size: 50px;
}
.wrapper {
display: flex;
- flex-direction: column;
- flex-wrap: wrap;
+ flex-direction: row;
}
.particule {
width: 1em;
@@ -48,17 +47,17 @@
<div class="wrapper"></div>
<script>
- var rows = 10;
+ var rows = 2;
var numberOfEls = rows * rows;
var duration = 1000;
- var stagger = 6;
+ var stagger = 100;
var midScreenX = window.innerWidth / 2;
var midScreenY = window.innerHeight / 2;
var radius = Math.sqrt(midScreenX * midScreenX + midScreenY * midScreenY);
var fragment = document.createDocumentFragment();
var wrapperEl = document.querySelector('.wrapper');
- wrapperEl.style.width = rows + 'em';
+ wrapperEl.style.width = numberOfEls + 'em';
wrapperEl.style.height = rows + 'em';
for (var i = 0; i < numberOfEls; i++) {
@@ -73,7 +72,7 @@
scale: [.9, .1],
direction: 'alternate',
loop: true,
- easing: 'spring(100, 100, 1, 0)',
+ easing: 'easeInOutQuad',
duration: duration,
startTime: ((numberOfEls + 1 - (i)) * stagger)
});
diff --git a/documentation/examples/anime-staggered-animations-02.html b/documentation/examples/anime-staggered-animations-02.html
index 1305e9c7..43402599 100644
--- a/documentation/examples/anime-staggered-animations-02.html
+++ b/documentation/examples/anime-staggered-animations-02.html
@@ -51,7 +51,7 @@
<script>
const wrapperEl = document.querySelector('.wrapper');
- const numberOfEls = 72;
+ const numberOfEls = 400;
const duration = 6000;
const delay = duration / numberOfEls;
const gap = 10;
@@ -86,9 +86,9 @@
rotate: [0, 90],
borderRadius: {
value: ['30%', '50%'],
- easing: 'easeInOutQuad'
+ easing: 'inOutQuad'
},
- easing: 'easeInOutSine',
+ easing: 'inOutSine',
direction: 'alternate',
duration: duration / 4
});
diff --git a/documentation/examples/anime-timeline-stresstest.html b/documentation/examples/anime-timeline-stresstest.html
new file mode 100644
index 00000000..efbc9615
--- /dev/null
+++ b/documentation/examples/anime-timeline-stresstest.html
@@ -0,0 +1,139 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Anime timeline | 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.2.0.js"></script> -->
+ <style>
+
+ body {
+ display: flex;
+ flex-wrap: wrap;
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ }
+
+ .wrapper {
+ display: flex;
+ flex-wrap: wrap;
+ justify-content: space-around;
+ align-items: center;
+ height: calc(100vh - 100px);
+ }
+
+ .el {
+ width: 10px;
+ height: 10px;
+ background: #FFF;
+ margin: 10px;
+ }
+
+ .controls {
+ display: flex;
+ position: fixed;
+ right: 0;
+ bottom: 0;
+ left: 0;
+ height: 100px;
+ background: white;
+ }
+
+ .buttons {
+ display: flex;
+ }
+
+ .buttons button {
+ width: 100px;
+ }
+
+ .timeline {
+ display: flex;
+ flex-grow: 1;
+ padding: 20px;
+ }
+
+ .progress {
+ flex-grow: 1;
+ }
+
+ </style>
+</head>
+<body>
+ <div class="wrapper"></div>
+ <div class="controls">
+ <div class="buttons">
+ <button class="play">Play</button>
+ <button class="pause">Pause</button>
+ <button class="restart">Restart</button>
+ </div>
+ <div class="timeline">
+ <input class="progress" type="range" min="0" max="100" step=".1" value="0">
+ </div>
+ </div>
+</body>
+<script>
+
+ var controlsProgressEl = document.querySelector('.controls .progress');
+
+ var tl = anime.timeline({
+ autoplay: false,
+ direction: 'alternate',
+ update: function(anim) {
+ controlsProgressEl.value = anim.progress;
+ },
+ begin: function(anim) {
+ console.log('tl begin');
+ },
+ complete: function(anim) {
+ console.log('tl complete');
+ }
+ });
+
+ document.querySelector('.controls .play').onclick = tl.play;
+ document.querySelector('.controls .pause').onclick = tl.pause;
+ document.querySelector('.controls .restart').onclick = tl.restart;
+
+ var wrapperEl = document.querySelector('.wrapper');
+ var numberOfEls = 1000;
+ var fragment = document.createDocumentFragment();
+
+ function createEl(i) {
+ var el = document.createElement('div');
+ el.classList.add('el');
+ var hue = Math.round(180 / numberOfEls * i);
+ el.style.backgroundColor = 'hsl(' + hue + ', 60%, 60%)';
+ tl.add({
+ targets: el,
+ scale: [0, 3],
+ duration: 5000,
+ easing: 'easeOutElastic(1, .05)',
+ }, !i ? 0 : '-=4990');
+ fragment.appendChild(el);
+ };
+
+ for (let i = 0; i < numberOfEls; i++) createEl(i);
+
+ wrapperEl.appendChild(fragment);
+
+ controlsProgressEl.addEventListener('input', function() {
+ tl.seek(tl.duration * (controlsProgressEl.value / 100));
+ });
+
+ </script>
+ <script src="../assets/js/stats.js"></script>
+</html>