Jump to content
Search Community

Change path during animation

roxzu test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

Hello ,

Im trying to do a animtion on scroll .
What I want to do is a dot that starts at the bottom of the pink path and as you scroll the dot it goes up and when it is at the intersection it changes path to purple.

I can't share my exact code but this is what I did overall.But the point doesn't go the other path and when i try whitout the tl.to(target) but gsap.to(target) that works witout the scrolltrigger.

I don't know if I was clear but i hope someone can help me 

let tl = gsap.timeline({
    scrollTrigger: {
        trigger: ".test",
        pin: ".test",
        start: "top center",
        end: "+3000 center",
        scrub: true,
    },
})

 

tl.to('.test-dot-1', {
    ...this.makeMotionPath(.43, .57,tl),
    duration: 1000,
});

 

 

 

makeMotionPath(start, end,tl) {
    return {
        motionPath: {
            path: '#path-3',
            align: '#path-3',
            start: start,
            end: end,
            alignOrigin: [0.5, .5],
        },
        onUpdate: function () {
            let progress = start + this.ratio * (end - start)
            let target = this.targets()[0];
            if (progress >= 0.47) {
                console.log('tl',tl)
                console.log(target)
                tl.to(target, {
                    motionPath: {
                        path: '#path-2',
                        align: '#path-2',
                        start: .47,
                        end: 1,
                        alignOrigin: [0.5, .5],
                    },
                    duration: 100,
                    onUpdate: function (){
                        console.log('test')
                    },
                });
            }
        },
    }
},

image.thumb.png.4b97d6e48672fc9e5cce0d97a5b19e73.png

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

  • Solution

I don't know how exactly your paths are drawn or where they start or end, but why not have two tweens one tweens from some where to the middle and the other tweens from the end of the previous point to some where else.

 

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

 

Even easier would be if you have some path drawn in your shape which is just a hidden path and that is the path it will follow. If you draw that shape from start to finish you can just tween from 0 to 1. Right now your lines are circles which go off screen, which makes it hard to figure out where the start and where the end is. The full circle is spread from 0 to 1 and it seems that the end of the path is at the right side 

 

Hope it helps and happy tweening! 

Link to comment
Share on other sites

I've figured out what made it so hard. Your paths are drawn in a counter clockwise direction.

 

I've stripped out all unnecessary code and set all dots to just over half way as you can see that is in the upper right corner and the way you want to animate is the other direction. So where you would normally would animate from 0 to 1 you want to animate from 1 to 0. Hope it helps and happy tweening, oh and welcome to the forum btw!

 

See the Pen MWLBdEL?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...