Tanuki Posted August 1, 2021 Share Posted August 1, 2021 I'm trying to implement a transition from an SVG (one or more Chinese characters) to a rect. I can set a rect position easily enough, but I can't seem to change either the position (important) or size of the Chinese character SVG without first wrapping it in another SVG (where I can set the x and y values). However, this is a really kludgy approach, since I still can't fine-tune the pos or size of the Chinese character SVG. <svg x="200" y="200"> <rect id="svg-src-rect" class="svg-src" x="70" y="70" // this works...:>) width="150" height="150" /> <!-- x,y positions do not affect actual position --> <path id="svg-target-hanzi" class="svg-target" x="70" y="70" // this does not work..:>( width="200" height="200" This is actually outside the scope of GSAP, but if anyone has run across this type of problem (and figured out a solution), that would be greatly appreciated. TBH, I'm new to working with SVG's outside of bootstrap, where I can control things vis a vis the bootstrap grid. Thx! See the Pen VwbdbwE by imtanuki (@imtanuki) on CodePen Link to comment Share on other sites More sharing options...
Solution GreenSock Posted August 2, 2021 Solution Share Posted August 2, 2021 <path> elements don't have an "x" or "y" attribute. That has nothing to do with GSAP - it's just how SVG works. There are two ways to control their position: Alter the path data itself (the stuff inside the "d" attribute). That's where all the coordinates are. Transforms (literally the "transform" attribute...but in GSAP you can set those with the "x" and "y" shortcuts). Example: gsap.set("#pathID", {x: 70, y: 50}); Does that answer your question? 3 Link to comment Share on other sites More sharing options...
Cassie Posted August 2, 2021 Share Posted August 2, 2021 You can do relative positioning by nesting SVG's...https://www.sarasoueidan.com/blog/mimic-relative-positioning-in-svg/ 1 Link to comment Share on other sites More sharing options...
Tanuki Posted August 2, 2021 Author Share Posted August 2, 2021 Jack, Cassie, Thx both for the quick replies! Re x,y attribs in path: Re x,y attributes - gsap.set works great! It seems that MorphSVGPlugin.convertToPath(srcRect) automatically picks up x,y attributes in a <rect> or other shape, so I can either set x, y, width, height in the <rect> tag or x, y, scaleX, scaleY with gsap.set. Re nested SVG's: as I mentioned in my initial post, I tried nested SVG's, but I wasn't getting any further control inside the child SVG. so I'll just go ahead and delete the child SVG, since gsap.set gives me the granularity of control that I need. Thx again! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now