Jump to content
Search Community

Animate only within scrollTrigger bounds

Romanus test
Moderator Tag

Recommended Posts

Hi,

 

Thanks for the super simple codepen example!

 

In the case of that particular example just use toggleActions:

gsap.to('.box',{
  x:200,
  yoyo:true ,
  repeat: -1,
  ease: "none",
  duration:2,
  scrollTrigger: {
    trigger:'.box',
    markers:true,
    toggleActions: "play pause play pause",
  }
})

From ScrollTrigger docs:

toggleActions

String - Determines how the linked animation is controlled at the 4 distinct toggle places - onEnter, onLeave, onEnterBack, and onLeaveBack, in that order. The default is play none none none. So toggleActions: "play pause resume reset" will play the animation when entering, pause it when leaving, resume it when entering again backwards, and reset (rewind back to the beginning) when scrolling all the way back past the beginning. You can use any of the following keywords for each action: "play", "pause", "resume", "reset", "restart", "complete", "reverse", and "none".

 

Let us know how it works.

Happy Tweening!

  • Thanks 1
Link to comment
Share on other sites

8 hours ago, Rodrigo said:

Hi,

 

Thanks for the super simple codepen example!

 

In the case of that particular example just use toggleActions:

gsap.to('.box',{
  x:200,
  yoyo:true ,
  repeat: -1,
  ease: "none",
  duration:2,
  scrollTrigger: {
    trigger:'.box',
    markers:true,
    toggleActions: "play pause play pause",
  }
})

From ScrollTrigger docs:

toggleActions

String - Determines how the linked animation is controlled at the 4 distinct toggle places - onEnter, onLeave, onEnterBack, and onLeaveBack, in that order. The default is play none none none. So toggleActions: "play pause resume reset" will play the animation when entering, pause it when leaving, resume it when entering again backwards, and reset (rewind back to the beginning) when scrolling all the way back past the beginning. You can use any of the following keywords for each action: "play", "pause", "resume", "reset", "restart", "complete", "reverse", and "none".

 

Let us know how it works.

Happy Tweening!

Thank you! This works great. But I got a little problem.

If the section is "pin", the markers leave, but the element remains.

Because of this, the element stops earlier than I expect.

Can this be fixed somehow?

See the Pen XWBvMPO by romanusname (@romanusname) on CodePen

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