Jump to content
Search Community

Snap property in ScrollTrigger

Klygor test
Moderator Tag

Recommended Posts

Hi people!

 

I'm currently doing a project where I have one big timeline controlled by ScrollTrigger. I want that when I scroll a little up or down the scroll go to the next label that i have in the timeline. But I have to scroll a lot when I use snap: "labels" or it goes back. Is there any way to do what I want? I have seen codepens where you can snap to the next section but I want only to the next label.

 

Thank you!

Link to comment
Share on other sites

Hey Klygor and welcome to the GreenSock forums. Currently ScrollTrigger doesn't have any built in functionality for this sort of thing. 

 

To do this sort of effect currently you'd need to create a ScrollTrigger, get its start and end positions, know or calculate where the labels are in terms of percentages of the total scroll distance, then in any scroll event within the relevant section disable the default scrolling and use a set scrollTo animation to get to that scroll position. It's definitely not a trivial task as is.

  • Like 1
Link to comment
Share on other sites

4 hours ago, ZachSaucier said:

Hey Klygor and welcome to the GreenSock forums. Currently ScrollTrigger doesn't have any built in functionality for this sort of thing. 

 

To do this sort of effect currently you'd need to create a ScrollTrigger, get its start and end positions, know or calculate where the labels are in terms of percentages of the total scroll distance, then in any scroll event within the relevant section disable the default scrolling and use a set scrollTo animation to get to that scroll position. It's definitely not a trivial task as is.

Wow! I thougth there was an easiest way to do it hahaha. Is there a way to calculate the percentage of where are the labels with gsap?, because I know where they are but not its percentage. I've already created the ScrollTrigger with end and start, all animations added and all labels too. 

 

Thank you !

Link to comment
Share on other sites

  • 5 months later...

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