Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Initial staggered loop proposal #194 #209

Julian Garnier584278c05fd8
diff --git a/anime.js b/anime.js
index 7ffac8d2..49f66891 100644
--- a/anime.js
+++ b/anime.js
@@ -712,6 +712,7 @@
instance.paused = true;
instance.began = false;
instance.completed = false;
+ instance.looped = false;
instance.reversed = direction === 'reverse';
instance.remaining = direction === 'alternate' && loops === 1 ? 2 : loops;
for (let i = arrayLength(instance.children); i--; ){
@@ -791,6 +792,7 @@
const insDelay = instance.delay;
const insCurrentTime = instance.currentTime;
const insReversed = instance.reversed;
+ if (instance.looped) engineTime += insDelay;
const insTime = minMaxValue(adjustTime(engineTime), 0, insDuration);
if (instance.children) syncInstanceChildren(insTime);
if (!instance.began && insTime >= insDelay) {
@@ -814,6 +816,7 @@
if (insTime >= insDelay) setCallback('run');
if (engineTime >= insDuration) {
if (instance.remaining) {
+ if (instance.direction === 'staggered') instance.looped = true;
startTime = now;
if (instance.direction === 'alternate') toggleInstanceDirection();
} else {
diff --git a/documentation/examples/anime-DOM-stress-test.html b/documentation/examples/anime-DOM-stress-test.html
index 092f2719..eac1a13c 100644
--- a/documentation/examples/anime-DOM-stress-test.html
+++ b/documentation/examples/anime-DOM-stress-test.html
@@ -29,6 +29,7 @@
height: 1rem;
margin: -.5rem 0 0 -.5rem;
border: 1px solid currentColor;
+ /*background-color: currentColor;*/
border-radius: 50%;
transform: scale(0);
}
@@ -42,7 +43,7 @@
var duration = 2000;
var toAnimate = [];
var radius = window.innerWidth < window.innerHeight ? window.innerWidth : window.innerHeight;
- var distance = radius / 4 <= 150 ? 150 : radius / 4;
+ var distance = radius / 4 <= 150 ? 150 : radius / 3;
var colors = ['#FF1461', '#18FF92', '#5A87FF', '#FBF38C'];
var createElements = (function() {
@@ -61,18 +62,28 @@
})();
var animate = function(el, i) {
- // var angle = (i * .05) * Math.PI;
- // var angle = anime.easings['easeInOutExpo'](i);
- var angle = i * 2;
- var delay = ((duration * 2) / maxElements) * i;
+ // var angle = (i * .01) * Math.PI;
+ // var angle = anime.easings['easeOutBack'](i);
+ var angle = i * 4;
+ // var delay = ((duration * 2) / maxElements) * i;
+ // var angle = i * 1000;
+ var delay = (duration / maxElements) * i * 2;
var a = anime({
targets: el,
- translateX: [0, Math.cos(angle) * distance],
- translateY: [0, Math.sin(angle) * distance],
+ translateX: [0, Math.sin(angle) * distance],
+ // translateX: [0, Math.cos(angle * i *.01) * distance],
+ translateY: [0,Math.cos(angle) * distance ],
+ // translateY: [0, Math.sin(angle * i *.01) * distance],
scale: [
- {value: [0, 2], duration: duration / 2, easing: 'easeOutBack'},
+ {value: [0, 4], duration: duration / 2, easing: 'easeOutBack'},
{value: 0, duration: duration / 2, delay: duration / 4, easing: 'easeInBack'}
],
+ // borderRadius: 0,
+ // opacity: 0,
+ // height: 100,
+ // width: 200,
+ // filter: 'blur(1px)',
+ rotate: 180,
offset : delay,
duration: duration,
easing: 'easeOutSine',
diff --git a/documentation/examples/anime-staggered-animations.html b/documentation/examples/anime-staggered-animations.html
new file mode 100644
index 00000000..2128fc29
--- /dev/null
+++ b/documentation/examples/anime-staggered-animations.html
@@ -0,0 +1,112 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>tests | 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 {
+ position: absolute;
+ opacity: 1;
+ width: 2px;
+ height: 30%;
+ transform-origin: 0% 100%;
+ background: white;
+ }
+ </style>
+</head>
+<body>
+ <div class="wrapper"></div>
+ <script>
+
+ const wrapperEl = document.querySelector('.wrapper');
+ const numberOfEls = 90;
+ const duration = 5000;
+ const delay = (duration / numberOfEls);
+ let els = [];
+
+ anime.easings['inOut'] = function(t) {
+ return Math.pow(Math.sin(t * 3), 3);
+ }
+
+ 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'
+ });
+ wrapperEl.appendChild(el.node);
+ els.push(el);
+ }
+
+ for (let i = 0; i < numberOfEls; i++) createEl(i);
+
+ // function handleVisibilityChange() {
+ // if (document.hidden) {
+ // els.forEach(function(el) {el.animation.pause()});
+ // } else {
+ // els.forEach(function(el) {el.animation.play()});
+ // }
+ // }
+
+ document.addEventListener('visibilitychange', handleVisibilityChange, false);
+
+ </script>
+ <script src="../assets/js/stats.js"></script>
+</body>
+</html>
diff --git a/documentation/examples/anime-tests.html b/documentation/examples/anime-tests.html
index 24e94b95..330ae78d 100644
--- a/documentation/examples/anime-tests.html
+++ b/documentation/examples/anime-tests.html
@@ -21,67 +21,29 @@
<!-- <script src="../assets/js/anime.1.3.js"></script> -->
<style>
body {
- position: absolute;
+ display: flex;
+ justify-content: center;
+ align-items: center;
width: 100%;
- height: 100%;
+ height: 100vh;
}
- div {
- position: absolute;
- top: 50%;
- left: 50%;
- width: 400px;
- height: 400px;
- margin: -200px 0 0 -200px;
- /*border-radius: 50%;*/
- background-color: #FBF38C;
+ .el {
+ position: relative;
+ width: 20px;
+ height: 20px;
+ background: white;
}
</style>
</head>
<body>
- <div></div>
+ <div class="el"></div>
+ <div class="el"></div>
<script>
-
- var seekAnim = anime({
- targets: 'div',
- translateX: [10, 250],
- duration: 1000,
- delay: 0,
- direction: 'normal',
- autoplay: false,
- update: function() { console.log('update') },
- begin: function() { console.log('begin') },
- run: function() { console.log('run') },
- complete: function() { console.log('complete') }
+ anime({
+ targets: '.el',
+ translateX: 100,
+ loop: true
});
-
- seekAnim.seek(0);
-
- // var tl = anime.timeline({
- // autoplay: true
- // });
-
- // tl.add({
- // targets: 'div',
- // scale: [
- // { value: '1', easing: 'linear', duration: 0 },
- // { value: '-1, 1', easing: 'linear', duration: 0 },
- // { value: '-2, 2', easing: 'easeInCubic', duration: 500 },
- // { value: '-1, 1', duration: 1000 }
- // ]
- // }).add({
- // targets: 'div',
- // translateX: [
- // { value: 300 },
- // { value: 400 }
- // ]
- // }).add({
- // targets: 'div',
- // translateX: [
- // { value: 500 },
- // { value: 600 }
- // ]
- // })
-
</script>
<!-- <script src="../assets/js/stats.js"></script> -->
</body>