Jump to content
Search Community

How to make observer animate more than once?

FrEZ test
Moderator Tag

Recommended Posts

Currently my observer is animating only once forwards/backwards and doesn't animate again. Also I want it to animate 3 times in a row and can't figure out how. I know that my function limits it to only once. Would appreciate if someone could help!

 

function previous() {
    animating = true;
    gsap.to(camera.position, {
        ...cameraPositionsX['first'],
        duration: 1,
 
    })
}
function next() {
    animating = true;
    gsap.to(camera.position, {
        ...cameraPositionsX['second'],
    })
}
Observer.create({
    target: window,
    type: "wheel, scroll",    // touch?
    onUp: () => !animating && previous(),
    onDown: () => !animating && next(),
    onComplete: () => animating = false
  });
Link to comment
Share on other sites

There's no such thing as onComplete on an Observer, so that's never getting called. I think you meant to put that on your tweens. 

 

Observer.create({
  onComplete:() => {...}, // <-- INVALID
  ...
});

So in the animation(s) you're creating in the next() and previous() methods, you'd just need to add an onComplete that sets animating back to false. 

 

I hope that helps.

Link to comment
Share on other sites

28 minutes ago, GreenSock said:

There's no such thing as onComplete on an Observer, so that's never getting called. I think you meant to put that on your tweens. 

 

Observer.create({
  onComplete:() => {...}, // <-- INVALID
  ...
});

So in the animation(s) you're creating in the next() and previous() methods, you'd just need to add an onComplete that sets animating back to false. 

 

I hope that helps.

That helped, thanks! But I still can't figure out how to make my onUp and onDown go through several functions, not just one(meaning, change camera positions more than once). I saw a codepen using indexes, but it was in react and was very hard to understand. 

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