Jump to content
Search Community

ScrollTrigger animating along a pth

LSchneiderman test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

I want to animate ball01 along the svg path, starting from behind ball02, continuing along the line and stopping at ball04. I think the svg will need to be pinned for it to stay in view while the animation is taking place. I'm using 

See the Pen OJMRYbd by delwinh (@delwinh) on CodePen

 as my model. What needs to change in the code for the animation to work?

See the Pen mdmNaGq by lschneiderman (@lschneiderman) on CodePen

Link to comment
Share on other sites

  • Solution

 

Hey there LSchneiderman,
 

You have two scrollTriggers, which is unnecessary - you're also looking for a trigger element with an ID of SVG which doesn't exist.

I've got rid of the extra scrollTrigger, added that ID to the SVG and also added align: '.cls-1' to the motionPath tween.

The align value aligns the ball to the path. If you remove it you'll see it starts from the balls original coordinates.

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



Hope this helps!

  • Like 4
Link to comment
Share on other sites

@Cassie

Thank you!!

 

I don't know if you can help me with this tweak, but when I incorporated the path into my larger project, the circle follows the path, but when it reaches the end, it jumps back to its original, beginning spot:

 

var action = gsap
      .timeline({
        defaults: { duration: 9 },
        scrollTrigger: {
          trigger: "#path-pin",
          start: "top top",
          end: "+=200%",
          pin: true,
          pinSpacing: true
        }
      })
      .to(".ball01", { duration: 0.01, autoAlpha: 1 })
      .from("#path", { drawSVG: 0 }, 0)
      .to(
        ".ball01",
        { motionPath: { path: "#path", align: '#path', alignOrigin: [0.5, 0.5] } },
        0
      );

 

How do I make that circle just stay at the end of the svg path once it has followed the path all the way?

 

  • Like 1
Link to comment
Share on other sites

There are a bunch of ways to do this. Here's one: 

See the Pen WNONMXP?editors=0110 by GreenSock (@GreenSock) on CodePen

 

Just create the ball animation up front and pause it. Then insert a callback into the timeline at the correct spot (2.48 seconds here) and then play() that animation if scrolling forward, or reverse() it if scrolling backward. 

 

For fun, I added a little scale animation and a more fun ease :)

 

Does that clear things up? 

  • Like 2
Link to comment
Share on other sites

Hey @LSchneiderman,

 

The progress runs from 0 to 1.
If the scrubbed animation has a duration of 1 sec (a good option), the position is identical to the progress.

Discover the 'dancing trees'  at 0.665 (its period of time is very small here in relation to 1 sec of the main animation): 

 

See the Pen KKWNvNL?editors=1010 by mikeK (@mikeK) on CodePen

 

Another fun option: the use of GSAP Draggable.hitTest() (part of GSAP draggable):

 

See the Pen mdwyrZO by mikeK (@mikeK) on CodePen

 

Happy tweening ...

Mikel

  • Like 2
Link to comment
Share on other sites

Those are excellent points, @mikel. I love that you come along and offer various other approaches! Not only can people learn from those, but they also may open up other opportunities or be more flexible for certain effects. 👍 

 

The reason I personally prefer the simplistic "find the spot by dragging the playhead on GSDevTools" solution is because it's much less costly performance-wise during the animation. Of course you'd never notice it in most cases but running the Draggable.hitTest() multiple times on every tick (so hundreds of times per second) is less than ideal. Sorry, I obsess about performance sometimes :)

  • Like 2
Link to comment
Share on other sites

Hey Jack,

 

GSAP Draggable.hitTest() might be a smart alternative for a little animation gimmick.

 

For a longer scrolling distance and some animations to be positioned,

I find the onUpdate/progress feature perfect for me and easy to use in the production phase.

 

Do not apologize, you are expected to always provide the most effective solution.

 

And ... thanks for the honor.

 

Happy positioning ...

Mikel

 

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