Jump to content
Search Community

Weird behaviour when animating an SVG circle cx & cy properties

Sig test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hey,
I'm trying to animate 3 circles from the center of an SVG to a specific position, to do so i'm animating the cx and cy properties but the animation seems wrong. Instead of starting from the center and animating to the specified position, the circles start from the right. Can anyone help me understand the issue?
I've tried changing the transform-origin of the circles but with no results.

The codepen link is:

See the Pen KKRvyBX by signoo (@signoo) on CodePen

Link to comment
Share on other sites

  • Solution

Welcome to the forums, @Sig!

 

I noticed several problems:

  1. You're trying to animate "cx" and "cy" attributes but you're treating them as regular CSS properties. Some browsers recognize that, others don't. I definitely would not recommend animating those that way. You should use the attr:{...} wrapper to tell GSAP you want to animate the actual attributes (not inline CSS properties). However...
  2. You're animating between two completely different units ("%" and "px"). That won't work with attributes - you should stay consistent. That's easy enough for you to convert. For example, you could change cx="50%" to cx="257.46" because your viewBox has a width of 514.919. However...

I personally think it'd be much cleaner to leave the cx/cy as-is and instead, animate the "x" and "y" transforms like this: 

See the Pen QWrMaXY?editors=1010 by GreenSock (@GreenSock) on CodePen

 

Minor notes:

  • You don't have to explicitly set the durations to 0.5 because that's the default anyway
  • You don't need to wrap everything in a setTimout() to get it to wait 2 seconds. Just add a delay: 2 to your timeline.
  • You don't need to pause the timeline initially and then seek(0).play() on the same tick. It's fine to do, but it's totally unnecessary. Animations play immediately from their beginning by default. 
  • "out" is the default kind of ease, so you can do "power4" instead of "power4.out". It's not "wrong" either way. I'm just looking for ways to simplify your code.

 

Does that help? 

  • Like 1
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...