Jump to content
Search Community

gsap.fromTo() with a non-linear path

James0r test
Moderator Tag

Recommended Posts

I see the MotionPathPlugin is for animating along a fixed path (I think). So maybe I'm looking for something different. I'm animating some text between points on the viewport using fromTo() and instead of taking a direct path, I want it to travel along a curve. 

 

To be clear, I'm not talking about easing/timing. 

 

Any help much appreciated.

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or Stackblitz that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

It might be super basic and perhaps textPath is the way to go, but just thought there might be some helpers that auto-magically help with this.

 

Here's my minimal reproduction: 

See the Pen mdajqeO by James0r (@James0r) on CodePen

 

I'm working with words transitioning from their place in a paragraph up to their final location. Because of this they will be at different X coordinates within the paragraph.

 

I want them to follow a smooth curved path to their final destination. Something like the images below:
image.thumb.png.b870d3ebfe46031f7b7f1fcb254307b9.png

image.thumb.png.b3d552392794998098f64284c8907786.png

image.thumb.png.b1fa731d2d66165b9dda1d81ed59f8f0.png

Link to comment
Share on other sites

I wouldn't recommend animating top and left - it's much cheaper to animate x and y (transforms). 

 

As for animating along a curved path, you can use MotionPathPlugin for that. You can pass in an Array of coordinates. Sorta like: 

// plot a curve through these coordinates. The target's current coordinates will automatically be added to the start:
motionPath: [{x:100, y:50}, {x:200, y:0}, {x:300, y:100}]

Pro tip: you can fake a curved path by using a different ease for x and y. For example, "none" for y and "power3.in" for x would give you something like that 2nd image. 

 

Good luck!

Link to comment
Share on other sites

On 10/1/2023 at 2:50 PM, GreenSock said:

I wouldn't recommend animating top and left - it's much cheaper to animate x and y (transforms). 

 

As for animating along a curved path, you can use MotionPathPlugin for that. You can pass in an Array of coordinates. Sorta like: 

// plot a curve through these coordinates. The target's current coordinates will automatically be added to the start:
motionPath: [{x:100, y:50}, {x:200, y:0}, {x:300, y:100}]

Pro tip: you can fake a curved path by using a different ease for x and y. For example, "none" for y and "power3.in" for x would give you something like that 2nd image. 

 

Good luck!

Thanks. I changed my fromTo() to use translate instead of fixed positioning, but I'm not sure how I would achieve the faked curved path with x and y if I'm using them already for my from and to coordinates. Can you provide an example?

Link to comment
Share on other sites

Hi @James0r, something like this? 

 

If you have further questions please post a demo with the code you've tried, that way we can see where you are in the process. Forking your pens is a great idea, so that you can fall back on earlier ideas if something is not working. Hope it helps and happy tweening! 

 

See the Pen BavPgZw?editors=1010 by mvaneijgen (@mvaneijgen) on CodePen

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