Jump to content
Search Community

Horizontal Scroll with Sticky Panels Effect

ssaruh test
Moderator Tag

Recommended Posts

Hi! I'm trying to achieve an effect similar to https://gallery.delivery/ or https://shadow-brand.com/, where there is horizontal scrolling but the sections stick to the left side of the page so that the next section overlaps it.



Here is my pen:


I've achieved the horizontal scrolling effect looking at other threads here, but not sure how to approach the stickiness aspect-- I've tried applying a class that would fix the position of the panels but that removes them from the flow and causes things to jump around. Are you able to horizontally pin each element as it reaches the left side of the screen? Haven't seen any examples of this. Not expecting anyone to solve the whole thing for me but if anyone could point me in the right direction or could suggest a method of doing this it would be super helpful!





See the Pen dyjeLYG by ssaruuuu (@ssaruuuu) on CodePen

Link to comment
Share on other sites

Hi @ssaruh and welcome to the GreenSock forums!


This is more related to the way the elements are animated. In this case you have to move each card it's own width times the card's index in the collection and the duration of each animation has to increase based on the same index. For that you can use function based values:

let scrollTween = gsap.to(sections, {
  xPercent: (i) => -100 * i,
  duration: (i) => 0.5 * i,
  ease: "none", // <-- IMPORTANT!
  scrollTrigger: {
    trigger: ".container",
    pin: true,
    markers: true,
    scrub: 0.1,
    //snap: directionalSnap(1 / (sections.length - 1)),
    end: "+=3000 bottom"

Unfortunately the container animation class toggle functionality goes a bit wonky and it doesn't work as expected:

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


You'll have to come up with a different custom logic to toggle that class, based on the progress of the ScrollTrigger instance on scrollTween. I tinkered with it quite a bit and couldn't come up with something solid and I don't have a lot of time to go through this right now.


Let us know if you have more questions.

Happy Tweening!

  • Like 1
Link to comment
Share on other sites

Thank you so much! This achieved the main effect I was looking for.


The only other thing I added was a conditional statement so that the last panel doesn't scroll all the way to the left, + making it responsive so it switches to a vertical scroll under 767px window.

See the Pen YzjvNXB by ssaruuuu (@ssaruuuu) on CodePen

  • Like 2
Link to comment
Share on other sites

  • 4 months later...

Hello dev,
I have used the same configuration as in the demo above but I get an empty space below the container which only reduces at the end of the scroll, making the section just below appear. I don't want that empty space underneath. What could it be ?


Link to comment
Share on other sites

@AntonioNB4 It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 


Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.


Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

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


If you're using something like React/Next/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.


Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

  • Like 1
Link to comment
Share on other sites

Hi @AntonioNB4 and welcome to the GreenSock forums!


Indeed without a minimal demo is really hard for us to know exactly what the issue could be.


Based on what you describe, you are pinning a specific container whose height is not the screen height, hence you see some separation between said container and the one right after  in the DOM.


In those cases is better to wrap the container of the horizontal animation and the next element in the same element and pin that particular wrapper.. Something like this:

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


Hopefully this helps. If you keep having issues, please create a minimal demo that clearly illustrates what's the issue you're having and where you're stuck.

Happy Tweening!

  • Like 1
Link to comment
Share on other sites

Great! Yes, that was the solution. I placed the section after within the same section where the horizontal scroll is located. I some questions: 
1) how do I upload the minimal code pen demo here ?
2) in the horizontal scroll sticky here is it possible to decrease the scroll speed ?
3) can I block the panels that scroll a few pixels before reaching the edge of the container (container start)?


Thanks to @Rodrigo and @GSAP Helper too.


Best regards.

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