Skip to content

Commit 875a3d6

Browse files
committed
Direction parameter is now properly changed when animation reverse
1 parent 90a3962 commit 875a3d6

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

documentation/examples/anime-timeline.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<button class="pause">Pause</button>
107107
<button class="reverse">Reverse</button>
108108
<button class="restart">Restart</button>
109+
<label>Is reversed : <input class="is-reversed"></input></label>
109110
</div>
110111
<div class="timeline">
111112
<input class="progress" type="range" min="0" max="100" step=".1" value="0">
@@ -122,17 +123,20 @@
122123

123124
var els = document.querySelectorAll('.el');
124125
var controlsProgressEl = document.querySelector('.controls .progress');
126+
var isReversedEl = document.querySelector('.is-reversed');
125127

126128
window.tl = anime.timeline({
127129
targets: els,
128130
duration: 800,
129131
delay: function(el, i) { return 75 * i; },
130132
update: function(anim) {
131133
controlsProgressEl.value = anim.progress;
134+
isReversedEl.value = anim.reversePlayback;
132135
},
133136
loopComplete: (a) => console.log('TL loop completed'),
134137
autoplay: true,
135-
easing: 'easeOutQuad'
138+
easing: 'easeOutQuad',
139+
direction: 'alternate'
136140
});
137141

138142
document.querySelector('.controls .play').onclick = tl.play;

documentation/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,6 @@ <h3 class="demo-title">Reverse</h3>
26832683
targets: '.reverse-anim-demo .el',
26842684
translateX: 270,
26852685
loop: true,
2686-
direction: 'alternate',
26872686
delay: function(el, i) { return i * 200; },
26882687
easing: 'easeInOutSine'
26892688
});

lib/anime.es.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,10 @@ function anime(params) {
938938
var promise = makePromise(instance);
939939

940940
function toggleInstanceDirection() {
941+
var direction = instance.direction;
942+
if (direction !== 'alternate') {
943+
instance.direction = direction !== 'normal' ? 'normal' : 'reverse';
944+
}
941945
instance.reversed = !instance.reversed;
942946
children.forEach(function (child) { return child.reversed = instance.reversed; });
943947
}
@@ -1136,8 +1140,8 @@ function anime(params) {
11361140

11371141
instance.play = function() {
11381142
if (!instance.paused) { return; }
1143+
if (instance.completed) { instance.reset(); }
11391144
instance.paused = false;
1140-
instance.completed = false;
11411145
activeInstances.push(instance);
11421146
resetTime();
11431147
if (!raf) { engine(); }

lib/anime.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,10 @@ function anime(params) {
940940
var promise = makePromise(instance);
941941

942942
function toggleInstanceDirection() {
943+
var direction = instance.direction;
944+
if (direction !== 'alternate') {
945+
instance.direction = direction !== 'normal' ? 'normal' : 'reverse';
946+
}
943947
instance.reversed = !instance.reversed;
944948
children.forEach(function (child) { return child.reversed = instance.reversed; });
945949
}
@@ -1138,8 +1142,8 @@ function anime(params) {
11381142

11391143
instance.play = function() {
11401144
if (!instance.paused) { return; }
1145+
if (instance.completed) { instance.reset(); }
11411146
instance.paused = false;
1142-
instance.completed = false;
11431147
activeInstances.push(instance);
11441148
resetTime();
11451149
if (!raf) { engine(); }

lib/anime.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,10 @@ function anime(params = {}) {
918918
let promise = makePromise(instance);
919919

920920
function toggleInstanceDirection() {
921+
const direction = instance.direction;
922+
if (direction !== 'alternate') {
923+
instance.direction = direction !== 'normal' ? 'normal' : 'reverse';
924+
}
921925
instance.reversed = !instance.reversed;
922926
children.forEach(child => child.reversed = instance.reversed);
923927
}
@@ -1116,8 +1120,8 @@ function anime(params = {}) {
11161120

11171121
instance.play = function() {
11181122
if (!instance.paused) return;
1123+
if (instance.completed) instance.reset();
11191124
instance.paused = false;
1120-
instance.completed = false;
11211125
activeInstances.push(instance);
11221126
resetTime();
11231127
if (!raf) engine();

0 commit comments

Comments
 (0)