Jump to content
Search Community

TransformOrigin on SVG rect clipPath

cotton test
Moderator Tag

Recommended Posts

I'm trying to animate a clipPath <rect> width from 0 to 100% using scrollTrigger and scrub and would like it to grow from the centre.

I've tried using transformOrigin which seems to work because it only fills 50% of the space so presume the other half is off screen and the centre is actually on the left of the window?

 

I managed to get it working using css transform-origin with toggleClass on click of a button but dropping it into GSAP seems to present a new problem.

 

I've attached a screen of the transforms applied, I'm wondering does GSAP affect the data-svg-origin attribute see here?

 

Any help would be greatly appreciated.

 

 

Screenshot 2020-06-10 00.06.51.png

See the Pen oNbbxEN by Cottonltd (@Cottonltd) on CodePen

Link to comment
Share on other sites

Hey cottoncreative and welcome to the GreenSock forums. Thanks for being a Club GreenSock member!

 

As @PointC likes to say, trouble-free SVG animations come down to three things:

  1. Asset prep
  2. Asset prep
  3. Asset prep

In this case I recommend using a viewBox on your SVG (so GSAP can know what the dimensions of the SVG are), using clipPathUnits="objectBoundingBox" on your clipPath, and explicitly sizing your rect. 

See the Pen MWKKQaO?editors=0100 by GreenSock (@GreenSock) on CodePen

 

Note that I also improved some of your CSS and JS.

  • Like 2
Link to comment
Share on other sites

Hi @ZachSaucier

 

Many thanks for that, wonderfully simple with the correct prep.

Apologies for the dumped CSS/JS, thank you for giving it a neaten.

 

This is my first big push into animating SVG/Clip-Paths so I'm glad I've got this as a grounding to build on now.

Are there cases when viewBox isn't recommended and what's a good resource for all these intricacies?

 

Thanks again
James

 

 

 

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