JavaScript animation engine
Better pause()
Julian Garnierd0133b590744
diff --git a/anime.js b/anime.jsindex 75ac901d..2b3e29c7 100644--- a/anime.js+++ b/anime.js@@ -697,31 +697,28 @@// Corelet activeInstances = [];- let pausedInstances = [];- let raf = 0;+ let raf;const engine = (() => {- function play() { raf = requestAnimationFrame(step); };+ function play() {+ raf = requestAnimationFrame(step);+ };function step(t) {- if (pausedInstances.length) {- activeInstances = filterArray(activeInstances, ins => !pausedInstances.includes(ins));- pausedInstances = [];- }if (activeInstances.length) {let i = 0;while (i < activeInstances.length) {const activeInstance = activeInstances[i];if (!activeInstance.paused) {- activeInstances[i].tick(t);+ activeInstance.tick(t);} else {- pausedInstances.push(activeInstance);+ const instanceIndex = activeInstances.indexOf(activeInstance);+ if (instanceIndex > -1) activeInstances.splice(instanceIndex, 1);}i++;}play();} else {- cancelAnimationFrame(raf);- raf = 0;+ raf = cancelAnimationFrame(raf);}}return play;@@ -910,8 +907,6 @@instance.pause = function() {instance.paused = true;- const i = activeInstances.indexOf(instance);- if (i > -1) activeInstances.splice(i, 1);}instance.play = function() {diff --git a/documentation/examples/anime-tests.html b/documentation/examples/anime-tests.htmlindex 1a5e65ba..4bd5c120 100644--- a/documentation/examples/anime-tests.html+++ b/documentation/examples/anime-tests.html@@ -41,10 +41,13 @@<div class="item color-02"></div><div class="item color-03"></div><script>- var tl = anime.timeline();- tl.add({- translateX: 100- })+ var color01El = document.querySelector('.color-01');+ color01El.addEventListener('mouseenter', function() {+ anime({ targets: this, scale: 2 });+ }, false);+ color01El.addEventListener('mouseleave', function() {+ anime({ targets: this, scale: 1 });+ }, false);</script></body></html>\ No newline at end of file