Jump to content
Search Community

Prevent Reverse of scrollTrigger scrub:true

s15199d test
Moderator Tag

Recommended Posts

How do I prevent reversing when the user scrolls back up the page?

 

gsap.to(".img-container", {
    scale: 1.8, x: "-30%", y: "30%",
    scrollTrigger: {
        trigger: "#home-hero",
        start: "-107px",
        end: "+=120%",
        //markers: true,
        pin: true,
        scrub: true
    }
});

 

Link to comment
Share on other sites

Are you saying you want the animation to only ever go forward and never backward, and you want it to "scrub" (but again, only in one direction)? So let's say you scroll forward 500px which (to make it simple) is 50% through the animation...and then you scroll backwards all the way to the start, you want the animation to stay stuck at 50%, right? And then if you scroll forward again 500px, absolutely nothing would happen? But then once you go forward more, like to 600px, it would scrub forward accordingly? 

Link to comment
Share on other sites

If my assumptions above are correct, I'd imagine it could look like this: 

let tween = gsap.to(".img-container", {scale: 1.8, xPercent: -30, yPercent: 30, paused: true});
ScrollTrigger.create({
  trigger: "#home-hero",
  start: "-107px",
  end: "+=120%",
  pin: true,
  onUpdate: self => {
    if (self.direction === 1 && self.progress > tween.progress()) {
      tween.progress(self.progress);
    }
  }
});

Does that help?

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