JavaScript animation engine
Add anime callbacks example
Julian Garnier53c46874cc17
diff --git a/documentation/examples/anime-callbacks.html b/documentation/examples/anime-callbacks.htmlindex f63d098b..bb8bb7b1 100644--- a/documentation/examples/anime-callbacks.html+++ b/documentation/examples/anime-callbacks.html@@ -42,6 +42,8 @@width: 100%;height: 100%;padding: 20px;+ font-size: 16px;+ line-height: 20px;text-align: left;font-family: monospace;}@@ -60,10 +62,49 @@width: 50%;height: 100%;padding: 20px;+ font-size: 16px;+ line-height: 20px;text-align: left;font-family: monospace;}+ .timeline {+ position: absolute;+ left: 0;+ right: 0;+ bottom: 0;+ height: 100px;+ background-color: #000;+ }++ .tl-needle {+ position: absolute;+ z-index: 2;+ top: 0;+ left: 0;+ bottom: 0;+ width: 2px;+ margin-left: -1px;+ background-color: #FFF;+ }++ .tl-animation {+ display: flex;+ justify-content: space-between;+ width: auto;+ height: 1rem;+ background-color: currentColor;+ border-radius: .5rem;+ border: 4px solid #000;+ }++ .tl-delay,+ .tl-end-delay {+ width: auto;+ height: 1rem;+ background-color: rgba(0,0,0,.5);+ }+</style></head><body>@@ -87,10 +128,16 @@{value: -200},{value: 200}],- delay: 2000,- endDelay: 2000,- duration: 1000,- easing: 'linear',+ rotate: {+ value: 720,+ easing: 'easeInOutCirc',+ duration: 3000,+ delay: 500+ },+ delay: 1000,+ endDelay: 1500,+ duration: 2000,+ easing: 'easeOutQuad',direction: 'alternate',//loop: 3,update: function(a) {@@ -98,9 +145,64 @@}});- console.log(animation);+ function animePlayer(instance) {++ function createEl(type, className, parentEl) {+ var el = document.createElement(type);+ if (className) el.classList.add(className);+ if (parentEl) parentEl.appendChild(el);+ return el;+ }++ var timelineEl = createEl('div', 'timeline', document.body);+ var needleEl = createEl('div', 'tl-needle', timelineEl);+ var animations = [];+ var colors = ['#FF1461','#FF7C72','#FBF38C','#A6FF8F','#18FF92','#1CE2B2','#5EF3FB','#61C3FF','#5A87FF','#8453E3','#C26EFF','#FB89FB'];+ var colorIndex = 0;++ function convertMStoEM(ms) { return ms / 100; }+ function convertEMtoMS(em) { return parseFloat(em) * 250; }++ function createAnimationLog(animObj) {+ var anim = animObj;+ anim.player = {};+ anim.player.animationEl = createEl('div', 'tl-animation', timelineEl);+ anim.player.delayEl = createEl('div', 'tl-delay', anim.player.animationEl);+ anim.player.endDelayEl = createEl('div', 'tl-end-delay', anim.player.animationEl);+ anim.update = function() {+ anime.setValue(anim.player.animationEl, {width: convertMStoEM(anim.duration) + 'em'});+ anime.setValue(anim.player.delayEl, {width: (anim.delay / anim.duration) * 100 + '%'});+ anime.setValue(anim.player.endDelayEl, {width: (anim.endDelay / anim.duration) * 100 + '%'});+ }+ anime.setValue(anim.player.animationEl, {color: colors[colorIndex]});+ colorIndex++;+ if (!colors[colorIndex]) colorIndex = 0;+ anim.update();+ animations.push(anim);+ return anim;+ }++ instance.pause();++ var playerAnimation = anime({+ targets: needleEl,+ translateX: convertMStoEM(instance.duration) + 'em',+ duration: instance.duration,+ direction: instance.direction,+ loop: instance.loop,+ easing: 'linear',+ update: function(a) {+ instance.seek(a.currentTime);+ }+ });++ instance.animations.forEach(createAnimationLog);++ }++ animePlayer(animation);- function log(animation, logEl) {+ function logCallbacks(animation, logEl) {var callbacks = ['begin', 'loopBegin', 'changeBegin', 'change', 'changeComplete', 'loopComplete', 'complete'];@@ -133,7 +235,7 @@}- log(animation, document.querySelector('.log'));+ logCallbacks(animation, document.querySelector('.log'));</script>