Jump to content
Search Community

How to update path size after MorphSVG is already initiated

Beverly Tang test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

I'm trying to make a background morph into an svg shape by starting with a rect and converting that to a path with MorphSVGPlugin.convertToPath('rect'). However, I'm initially setting the rect size based on the page size (to look like a background color). 

How would I make this responsive to page resize? After the rect is converted to a path, I tried creating a new rect but morphSVG doesn't work with the newly replaced path.

 

Is there a way to make this work? (this is a scrolling animation)

 

Update: When I repeat the timeline action after the resize, it'll sort of work but the morphing is not smooth. 

See the Pen zYPNpxe by sublimina (@sublimina) on CodePen

Link to comment
Share on other sites

Do you need the SVG background to be a fixed height, or can that scale with the browser as well? If not, my suggestion would be to set the viewBox for the SVG along with the width value, so that it naturally is responsive with the page.

 

If this isn't viable, you'll need to .kill() the animation and possibly ScrollTrigger on resize, and reset it based on the new width (you are currently just adding a new tween to the timeline, which is likely what's giving you jumpy results).

Another option would be to dive into preserveAspectRatio, and use a functional end scaleX tween based on viewport width to get your final shape the way you want it. I do not have an example of this, but I imagine it should/could work (in theory and my imagination at least):

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio

https://www.digitalocean.com/community/tutorials/svg-preserve-aspect-ratio

 

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