Jump to content
GreenSock

codeSanjay

GSAP Horizontal scroll

Moderator Tag
Go to solution Solved by GreenSock,

Recommended Posts

I have horizontal slider initiated using GSAP. But the problem is when horizontally scrolled it triggers other section too. What I wanted is that the sections below horizontal scroll to be only triggered when come to the original position. Also I want the whole document to be pinned. Is it possible to do with GSAP? As always I am very hopeful to you guys. Thanks in advance.

See the Pen BarqbaY?editors=1111 by devSanjay (@devSanjay) on CodePen

Link to comment
Share on other sites

Hi there!

 

Thanks for the clear demo - appreciated.

How about something like this. Using the previous scrollTriggers end point as the starting point for the next one?

See the Pen GRxYebY by GreenSock (@GreenSock) on CodePen

  • Like 1
Link to comment
Share on other sites

Thankyou @Cassie for your reply. But the solution that you provided won't work if there comes another section in between those two sections.

Link to comment
Share on other sites

  • Solution

Hi  @codeSanjay. You just forgot to set the pinnedContainer value: 

See the Pen jOzQqRK?editors=1010 by GreenSock (@GreenSock) on CodePen

 

The ScrollTrigger needs to know that you're pinning the container so that it can offset the start/end values accordingly. 

 

Does that clear things up? 

  • Like 1
Link to comment
Share on other sites

Thankyou @GreenSock . Your solution perfectly fits for my problem.  But the container of horizontal sliders behave weirdly on enterBack condition. It doesn't fire as soon as it meets the condition but fires later on. Is there a way to fix it?

See the Pen wvmYOvm?editors=1010 by devSanjay (@devSanjay) on CodePen

Link to comment
Share on other sites

I don't understand what you mean. You set the trigger to ".horizontal-sliders" and you didn't set an "end", so it uses the default of "right left", meaning when that trigger's right side hits the left side of the screen (or the equivalent distance). Sorry, I'm just not clear on what you're expecting or what you think is wrong. 

Link to comment
Share on other sites

If you only want the color to change on enter back you can use a callback?
 

onEnterBack: () => {
  gsap.to('.horizontal-sliders', {
    backgroundColor: "red",
  })
}

 

  • Like 2
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.
×