Jump to content
Search Community

MorphSVG bouncy line during drag

tailbreezy test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Basically I want to play from current path to this.y in Draggable.

The thing is want to play an tween instead of setting values, because I want to add eases and such.

 

It would be like mapping mapRange("M 0,0 H 280 C 280,0 280,72...", "M 0,0 H 280 C 380,0 380,72...",0,1) 

and then use the result in morphSVG.

Link to comment
Share on other sites

Managed to pull it off, not sure why it is not playing correctly here.

You can get an idea from the code.

 

Codepen Chrome throws some weird exception. It plays proper on firefox (at least here)

 

Is there any other way to achieve this? Cleaner perhaps and without codepen issues :D

Link to comment
Share on other sites

In the future, please make sure to use the "fork" button on CodePen when creating new versions of demos for these forums. That way context is not lost :) 

 

2 hours ago, tailbreezy said:

Chrome throws some weird exception

I think you found a bug. We'll continue investigating. In the mean time you can use the vanilla JS version: 

paths.current = document.querySelector('.fromRef').getAttribute('d')

 

2 hours ago, tailbreezy said:

Is there any other way to achieve this?

Well, the difficulty is that you want it to both be controlled by the drag position and animate once the drag has been completed. So the closer your value is during the drag, the less bouncy you can get when the drag is done. If you removed the actual drag aspect and just animated with an elastic ease to the final state from the beginning state it'd be much more bouncy. See what I mean?

 

If you just limited the updates of your morph to just the times when it snaps it'd be significantly better but still not super bouncy:

See the Pen jOMJgZv?editors=1010 by GreenSock (@GreenSock) on CodePen

 

Additionally, if you wanted to have the circle/drag element itself be smooth and only the bouncy-ness snap you could do that by not using liveSnap but instead do the snappping inside of the onDrag function (when setting the new progress).

  • Like 3
Link to comment
Share on other sites

  • Solution
2 hours ago, ZachSaucier said:

I think you found a bug. We'll continue investigating. In the mean time you can use the vanilla JS version: 

It's actually not a bug. gsap.getProperty() is primarily for CSS properties or normal (direct) properties of object, not attributes but it does fall back to attributes when nothing is found. The issue is simply that Chrome reports the getComputedStyle() with "path(...)" wrapped around the value. Like Zach said, if you want to get the attribute, it's best to just do element.getAttribute(...).

 

Here's an approach that's simpler in some ways, but more advanced in others: 

See the Pen poEBzaJ?editors=0010 by GreenSock (@GreenSock) on CodePen

 

It's more performant because it's simply animating the progress of a single tween that's doing the interpolation. I crafted an elastic ease out that has a very slight ease in at the beginning to smooth things out, and then I created a special ease that goes from -1 to 2 instead of 0 to 1 so that we have room to overshoot the values with elastic and not get clipped. Seems to work relatively well. 

 

Happy tweening!

  • Like 4
Link to comment
Share on other sites

  • ZachSaucier changed the title to MorphSVG bouncy line during drag

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