Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Update staggered animations example

Julian Garnier9ac2fa5a7bd0
diff --git a/documentation/examples/anime-staggered-animations.html b/documentation/examples/anime-staggered-animations.html
index 58fa2a0d..7edc2fc8 100644
--- a/documentation/examples/anime-staggered-animations.html
+++ b/documentation/examples/anime-staggered-animations.html
@@ -31,18 +31,19 @@
.wrapper {
position: relative;
display: flex;
- flex-direction: column;
+ align-items: center;
flex-wrap: wrap;
width: 1px;
- height: 80vh;
+ height: 100vh;
}
.el {
position: absolute;
opacity: 1;
width: 2px;
- height: 30%;
- transform-origin: 0% 100%;
+ height: 200px;
+ margin-top: -100px;
+ transform-origin: 50% 100%;
background: white;
}
</style>
@@ -53,73 +54,42 @@
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);
- }
+ const duration = 6000;
+ const delay = duration / numberOfEls;
var tl = anime.timeline({
- loop: true,
- update: function() {
- // console.log('upd');
- }
+ duration: delay,
+ easing: 'linear',
+ complete: function() { tl.restart(); }
});
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%)';
+ let el = document.createElement('div');
+ const rotate = (360 / numberOfEls) * i;
+ const translateY = -50;
+ const hue = Math.round(360 / numberOfEls * i);
+ el.classList.add('el');
+ el.style.backgroundColor = 'hsl(' + hue + ', 40%, 60%)';
+ el.style.transform = 'rotate(' + rotate + 'deg) translateY(' + translateY + '%)';
tl.add({
- complete: function() {
- console.log('complete');
+ begin: function() {
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,
+ targets: el,
+ backgroundColor: 'hsl(' + hue + ', 60%, 80%)',
+ rotate: rotate + 10 +'deg',
+ translateY: translateY + 10 + '%',
+ scale: 1.25,
+ easing: 'easeInOutSine',
+ direction: 'alternate',
+ duration: duration * .1
});
- },
- duration: 0,
- offset: delay * i,
+ }
});
- console.log(delay * i);
- wrapperEl.appendChild(el.node);
- els.push(el);
+ wrapperEl.appendChild(el);
};
- console.log(tl);
-
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>
diff --git a/documentation/examples/anime-tests.html b/documentation/examples/anime-tests.html
index ecbcf7a9..407a5fe7 100644
--- a/documentation/examples/anime-tests.html
+++ b/documentation/examples/anime-tests.html
@@ -41,39 +41,37 @@
<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');}
- // });
- // console.log(duration0.currentTime);
- // animation.seek(0);
- // console.log(animation.currentTime);
+ var seek0 = anime({
+ targets: '.color-01',
+ translateY: [300, 100],
+ // loop: true,
+ autoplay: false,
+ update: function(anim) { console.log('seek0 update', anim.currentTime);},
+ begin: function(anim) { console.log('seek0 begin', anim.currentTime);},
+ run: function(anim) { console.log('seek0 run', anim.currentTime);},
+ complete: function(anim) { console.log('seek0 complete', anim.currentTime);}
+ });
+ // seek0.seek(0);
+ var duration0 = anime({
+ targets: '.color-04',
+ translateY: [200, 300],
+ loop: true,
+ autoplay: false,
+ duration: 0,
+ update: function() { console.log('duration0 update');},
+ begin: function() { console.log('duration0 begin');},
+ run: function() { console.log('duration0 run');},
+ complete: function() { console.log('duration0 complete');}
+ });
+
var tl = anime.timeline({
targets: '.color-08',
- autoplay: true,
easing: 'easeOutExpo',
duration: 500,
autoplay: false,
- // update: function(anim) { console.log('TL update', anim.currentTime);},
+ 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);},
+ run: function(anim) { console.log('TL run', anim.currentTime);},
complete: function(anim) { console.log('TL complete', anim.currentTime);}
});