Jump to content
Search Community

Best way to get SVG current rotation value?

ada601 test
Moderator Tag

Recommended Posts

Since animating an SVG element with rotation produces a matrix, what is the best way to obtain the current rotation value in an onUpdate callback?

 

Currently, the only way I found that works is to use the getProperty method. Is that the only way? If not, is it the appropriate way?

 

Thank you in advance.

Link to comment
Share on other sites

It was a little hard to find it, actually! I'm coming from anime.js where I would just look at the current tween on update.

 

When I got here I found discussions about using "{self}" in onUpdateProps and that added a little to my confusion. Then investigating this in the callback left me empty handed.

 

No drawbacks, I just wanted to be sure that was the best way to do it.

Link to comment
Share on other sites

Another approach would be to use this.targets() inside of a listener to get the current target(s) and then get the value from that. It's still probably best to use getProperty though :) Just with the target from this.targets() (if it needs to be more dynamic than a string selector or whatever you are using as the tween's target). 

 

"{self}" is from older versions of GSAP and isn't supported in GSAP 3.

Link to comment
Share on other sites

1 minute ago, ZachSaucier said:

Do you happen to still have links to the thread(s) that you were looking at? It might be good for us to include a post about .getProperty in them so that future readers can find it more easily.

 

If there would have been a little tip alongside discussion of rotate anywhere the getting started docs that probably would have save me an hour. Everything else I read was via google and pretty old...

Link to comment
Share on other sites

17 minutes ago, ada601 said:

If there would have been a little tip alongside discussion of rotate anywhere the getting started docs that probably would have save me an hour.

I added a little section to the getting started article: https://greensock.com/get-started/#get-property

 

Do you think that's sufficient for future readers? Sorry for the trouble finding this information caused you.

Link to comment
Share on other sites

Quote

If you want to get the current value of a specific element, you can (at any time, of any element) use GSAP's .getProperty() method.

I just might add that this works even in arrow functions - since you just talked about how getting targets *doesn't*.

 

I you made an excellent addition to the docs!

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...