Jump to content
GreenSock

rwv99

Inline SVG circles on a circle

Recommended Posts

Hello all,

 

Have been searching the forum, but can't find an answer to something that can't be complicated, I'm sure. (Can't get it figured out, though.) Check the Pen: I'm trying to 'shoot' small circles on a larger circle. All the elements are inline SVG (part of a larger drawing), using SVG 'transform: rotate()' on the small circles.

 

If you comment out the 'staggerFrom' you'll see what it's supposed to look like. With the tween active the transforms on the small circles are somehow skipped.

 

Any idea anybody?

 

Thanks,

Ruud.

See the Pen zKmJJo by rwv999 (@rwv999) on CodePen

Link to comment
Share on other sites

That's expected behaviour. The long story short is that GSAP uses x and y as a proxy to transform translate(), they are not the same thing as the x and y in SVG, when you tween the x and y in your pen, you are really overwriting the transform rotate() with new values. 

 

You can do one of two things, reposition your inner circles using transform translate() or use the attrPlugin like so:

TweenMax.staggerFrom(menuItems, 2, {attr:{cx:2000, cy:2000}, autoAlpha: 0, ease: 'Power4.easeOut'}, 0.5);

Does that help?

  • Like 5
Link to comment
Share on other sites

Hey Dipscom,

 

Yes, that helps a lot, thanks for the explanation! Should have thought of that myself, animating the SVG attributes, not the CSS. What I don't get is that now the circles seem to come from different starting positions, although the tween uses just one (cx:2000, cy:2000). That also expected behaviour?

 

Thanks,

Ruud.

Link to comment
Share on other sites

Yes it would be, remember you are rotating the inner circles. SVG is rather confusing when it comes to that because of its viewBox attribute and how it behaves, I can't go over it in detail now as I'm away from the computer but once I have a chance, I'll link to a couple of blog posts that describe the viewBox and its behaviour.

  • Like 1
Link to comment
Share on other sites

...of course, rotating an element creates a new (rotated) user coordinate space. (Keep forgetting that every now and then...)

 

Thanks for pointing stuff out,

Ruud.

 

(PS. Link refers to Joni Trythall's Pocket Guide to Writing SVG, also an excellent SVG resource, as are Sara S's articles.)

Link to comment
Share on other sites

There you go. You lot got it all sorted amongst yourselves. ;)

Link to comment
Share on other sites

Did you get it working like you wanted to?

 

Here's a demo showing how to position elements around a circle...

See the Pen e86dc71e2406793fb7b899b73f881f67?editors=1010 by osublake (@osublake) on CodePen

 

Remove your transforms, and yours can work the same...

See the Pen WoWoMv?editors=0010 by osublake (@osublake) on CodePen

  • Like 3
Link to comment
Share on other sites

Was struggling a bit to get back to the original design, so this helps a lot. I like the efficient coding, definitely have to brush up my trigonometry a bit more...

 

I like the dynamics on this forum, thanks for the input!

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.
×