Jump to content
Search Community

Detect scrolling within pinned area

mindfailure test
Moderator Tag

Recommended Posts

How can I trigger a function if a user scrolls more than 50px within a pinned area?

 

Example code for the pinned area:

 

I assume that this would be achieved using onEnter and a function

  gsap.to(container, {
    scrollTrigger: {
      trigger: container,
      pin: true,
      onEnter: () => {
        /**
         * If scroll more than say 50px
         * trigger hpNext();
         */

      },
    },
  });

Thanks

 

 

Link to comment
Share on other sites

Hi mindfailure,

 

You could use a nested element inside of the container and create another ScrollTrigger to make your call.

 

Or you can just check to see how far it's scrolled in onUpdate.

 

onUpdate(self) {
  console.log(self.scroll() - self.start)
}

 

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