Jump to content
Search Community

Morph + Bezier

mk1 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

I want to move the black dot from the start of the motion path to it's end and than back. However my test case behave not as expected. Can you guys take a look?

 

As I can see when selecting the dot element in the console it moving over a path with same shape but misplaced

See the Pen MJgdaX by Nikolaus91 (@Nikolaus91) on CodePen

Link to comment
Share on other sites

There are a few problems I noticed:

 

You forgot to tell the pathDataToBezier() to align the data with the dot. See the docs at https://greensock.com/docs/#/HTML5/GSAP/Plugins/MorphSVGPlugin/pathDataToBezier/ (the "align" property)

 

You set the transform to percentage values directly in CSS, but it's impossible for GSAP to discern that because the browser always reports computed values in pixels (actually, as a matrix() or matrix3d()) - it's always best to set that explicitly via GSAP, like with a TweenLite.set() call. That way, GSAP understands that your intent is percentage-based. So your code should look like:

var dot = document.getElementById('cls-2');
var circle = document.getElementById('cls-1');
TweenLite.set(dot, {xPercent:-50, yPercent:-50});

var path = MorphSVGPlugin.pathDataToBezier("#cls-1", {align:dot});

TweenMax.to(dot, 5, {bezier:{values:path, type:"cubic"}, transformOrigin: "50% 50%", ease:Linear.easeNone, repeat:-1});

Better?

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