svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
11.04k stars 1.08k forks source link

reverse doesn't work as expected #1158

Closed ischurov closed 1 year ago

ischurov commented 3 years ago

Bug report

I'm trying to reproduce the documentation on timeline().reverse() and it doesn't work as described there (or I don't understand what is written in the docs).

Fiddle

Fiddle

Explanation

Thanks a lot!

Fuzzyma commented 3 years ago

It seems what you are looking for is the reverse for one animation and not the whole timeline which you can simply do with rect.animate().move(...).reverse(). However you can also reverse the whole timeline but that basically means playing it backwards. So if you are at position t=0 and playing it backwards it stops immediately because its finished. You would need to seek to a different time first in order to play it backwards. I added a button to the example to show what I mean.

https://jsfiddle.net/Fuzzy/zwf30ond/

ischurov commented 3 years ago

Hi, @Fuzzyma , thanks for quick reply! That's actually what I was thinking about (particularly, I understood that if I invoke timeline().reverse() during the animation, it stops and reverses animation until t=0 is reached), but the docs said otherwise (at least, in my reading), so I start thinking it's a possible bug. Thanks for the hint that I can reverse one particular animation!

Probably, we can change the documentation in some way to make it obvious for the newcomers like myself?

Currently, it reads

// will run from 100,100 to rects initial position
rect.animate(3000).move(100, 100)
rect.timeline().reverse()

It seems to me that these particular two lines should do what is said in the comment, i.e. start animation that will run from 100, 100 to rects initial position.

Probably, we can include more thorough example like you provided in the fiddle?

Thanks again!

Fuzzyma commented 3 years ago

Yeah this example is really misleading and needs be improved.

davidfregoli commented 3 years ago

Hello @Fuzzyma, I'm finding it very hard to understand then how to reverse a completed animation (timeline)?

Fuzzyma commented 1 year ago

Here is an example that explains how to do it: https://jsfiddle.net/7rtweb9c/