Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Fix timeline playback on same targets

Julian Garniera9a819d068e3
diff --git a/anime.js b/anime.js
index 1318c77c..750f2aeb 100644
--- a/anime.js
+++ b/anime.js
@@ -700,6 +700,8 @@
instance.animatables[id].target.style[transformString] = transforms[id].join(' ');
}
}
+ instance.currentTime = insTime;
+ instance.progress = (insTime / instance.duration) * 100;
}
function setCallback(cb) {
@@ -714,28 +716,26 @@
function setInstanceProgress(engineTime) {
const insDuration = instance.duration;
- const insDelay = instance.delay;
+ const insOffset = instance.offset;
const insCurrentTime = instance.currentTime;
const insReversed = instance.reversed;
const insTime = minMaxValue(adjustTime(engineTime), 0, insDuration);
- instance.currentTime = insTime;
- instance.progress = (insTime / insDuration) * 100;
- if (insTime <= insDelay && insCurrentTime !== 0) {
- setAnimationsProgress(0);
- // console.log('0');
- if (insReversed && insTime <= 0) countIteration();
- }
- if (insTime > insDelay && insTime < insDuration) {
+ if (insTime > insOffset && insTime < insDuration) {
setAnimationsProgress(insTime);
if (!instance.began) {
instance.began = true;
setCallback('begin');
}
setCallback('run');
- }
- if (insTime >= insDuration && insCurrentTime !== insDuration) {
- setAnimationsProgress(insDuration);
- if (!insReversed) countIteration();
+ } else {
+ if (insTime <= insOffset && insCurrentTime !== 0) {
+ setAnimationsProgress(0);
+ if (insReversed) countIteration();
+ }
+ if (insTime >= insDuration && insCurrentTime !== insDuration) {
+ setAnimationsProgress(insDuration);
+ if (!insReversed) countIteration();
+ }
}
if (engineTime >= insDuration) {
if (instance.remaining) {
diff --git a/documentation/examples/anime-DOM-stress-test.html b/documentation/examples/anime-DOM-stress-test.html
index af65e937..c26a9a3f 100644
--- a/documentation/examples/anime-DOM-stress-test.html
+++ b/documentation/examples/anime-DOM-stress-test.html
@@ -31,7 +31,7 @@
<body></body>
<script>
- var maxElements = 1;
+ var maxElements = 350;
var duration = 1500;
var toAnimate = [];
var radius = window.innerWidth < window.innerHeight ? window.innerWidth : window.innerHeight;
diff --git a/documentation/examples/anime-logo-animation-timeline.html b/documentation/examples/anime-logo-animation-timeline.html
index c5ca7b9d..67e77cc5 100644
--- a/documentation/examples/anime-logo-animation-timeline.html
+++ b/documentation/examples/anime-logo-animation-timeline.html
@@ -44,8 +44,7 @@
top: 0;
left: 240px;
}
- .dot-e-in,
- .dot-e-out {
+ .dot-e {
bottom: 0;
right: 0;
}
@@ -170,14 +169,7 @@
</g>
</svg>
</div>
- <div class="dot dot-e-in">
- <svg viewBox="0 0 42 42">
- <g fill="none" fill-rule="evenodd">
- <rect width="40" height="40" x="1" y="1" fill="#FFFFFF" rx="20"/>
- </g>
- </svg>
- </div>
- <div class="dot dot-e-out">
+ <div class="dot dot-e">
<svg viewBox="0 0 42 42">
<g fill="none" fill-rule="evenodd">
<rect width="40" height="40" x="1" y="1" fill="#FFFFFF" rx="20"/>
@@ -205,7 +197,7 @@
logoAnimation
.add({
- targets: '.dot-e-in',
+ targets: '.dot-e',
translateX: { value: -600, duration: 520, delay: 200, easing: 'easeInQuart' },
scale: [
{ value: [0, 1], duration: 200, easing: 'easeOutBack' },
@@ -233,7 +225,7 @@
duration: 1
})
.add({
- targets: '.dot-e-out',
+ targets: '.dot-e',
translateX: { value: [-100, 0], duration: 500, easing: 'easeOutQuart' },
scale: [
{ value: [0, 1], duration: 200, easing: 'easeOutBack' },
diff --git a/documentation/examples/anime-playback.html b/documentation/examples/anime-playback.html
index 4ad86401..f3fe0dca 100644
--- a/documentation/examples/anime-playback.html
+++ b/documentation/examples/anime-playback.html
@@ -55,7 +55,7 @@
simpleTL.add({
targets: '.timeline .item',
translateX: 200,
- delay: function(el, i) { return 50 * i; },
+ delay: function(el, i) { return 1000 + (50 * i); },
begin: function(a) {
a.animatables.forEach(function(ani) {
ani.target.classList.add('color-08');
@@ -70,9 +70,9 @@
simpleTL.add({
targets: '.timeline .item',
- translateX: 400,
+ translateX: [200, 400],
scale: 1.5,
- delay: function(el, i) { return 50 * i; },
+ delay: function(el, i) { return 1000 + (50 * i); },
begin: function(a) {
a.animatables.forEach(function(ani) {
ani.target.classList.add('color-12');