Jump to content
Search Community

Morph once, wait a couple of seconds, then morph back to the original SVG path?

greencat test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi and welcome to the GreenSock forums.

 

The tricky thing here is that once you morph the circle it is no longer a circle shape, its a hippo shape.
 
What I would suggest is that you store a reference to the path data that makes the circle (before it ever gets morphed)
 
Please look at this example
 
// convert the <circle> to a path
var circle = MorphSVGPlugin.convertToPath("#circle")[0];
// grab all the path data from the circle
var circlePath = circle.getAttribute("d");
 
var tl = new TimelineLite();
tl.to(circle, 1, {morphSVG:"#hippo"})
  .to(circle, 1, {morphSVG:circlePath});
 
 
 
 
here is another example where the hippo morphs into a bunch of other animals and then back to the hippo shape using a similar technique
 
  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Hi Greencat,

 

Just wanted to update you on a new solution for this problem.

Whenever you morph a path we now save the original path data on a data-original attribute of that path so that MorphSVGPlugin can grab it later.

 

<path id="circle"  d="M409.6,198.066l26.833,54.369l60,8.719l-43.417,42.321l10.249,59.758L409.6,335.019
l-53.666,28.214l10.249-59.758l-43.417-42.321l60-8.719L409.6,198.066z" data-original="M490.1,280.649c0,44.459-36.041,80.5-80.5,80.5s-80.5-36.041-80.5-80.5s36.041-80.5,80.5-80.5
S490.1,236.19,490.1,280.649z"></path>

 

So taking an example above of morphing a circle into a few animals and then back to a circle, you no longer have to save a reference to the original circle shape yourself (as I previously recommended) you can just do

 

tl.to(circle, 1, {morphSVG:"#elephant"}, "+=1")
  .to(circle, 1, {morphSVG:circle}, "+=1");
 
 
This feature is implemented in version 0.5.0 which you can download now and the "CodePen Safe" version that we use in all of our demos.
 
Special thanks to Elliot Geno for the suggestion.

 

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