I have started learning GSAP recently and have been loving it. However, I have been experimenting with ScrollTrigger now and likely due to my own design choices it is not quite working. To whomever takes the time to help me with this, thank you so much in advance 🙏 And apologies for the broken CodePen, I added it anyways in case it helped understanding the description of the problem better, but it was really hard to recreate a Next Typescript React Tailwind project within a codepen.... I am new to web dev so I don't exactly have that 'mindset' yet so also apologies for the spaghetti code and appraoches hhaha.
My project uses React with Next. The problem i'm having is likely due to the fact that I use a scroll ref for scroll context instead of the window scroll. I'm doing this because the website consists of 3 layers. 1. The main background, this (ideally) would change colors with ScrollTrigger. I have not yet done this as I have encountered the problem with ScrollTrigger in a different component, but my idea was to attach a ScrollTrigger to each section and based on enter and leave change the color. 2. The content background, this just sits on top and is a padded div that has a different constant background color. The key thing is that this is where all of the content (layer 3) lies, and so I need to have overflow-y-auto here, such that when you scroll you scroll the content/children within this div. Because of this for any ScrollTrigger animation I need a ref to this div, that I have within context so that I can provide it to the children below.
Now the problem is related to the pinning of a section in layer 3 to create a horizontal scroll effect with some other animations I have in mind. The first problem with pinning here is that I get a wobbly effect when I try to scroll the section. I found a similar question on the forums at
However, it seemed to be quite related to PIXI which I do not use. Theres also the first solution provided that sets pinTyped to fixed but I do need to enable clicking and mouse interaction within this section so I cannot simply disable pointer events. The second problem is that while I am in this section, I am still scrolling the section and so even if it did work I would end up at the bottom of the page upon exit.
I have tried quite a few things so far but to no avail :(... What I currently have is: Upon entering, use a scrolltrigger to pin and set a state of isPinned. This isPinned. When scrolling in this area, the actual event will .preventDefault() and instead add to the h(orizontal)ScrollContainer.scrollLeft, to some extent adding this middleman that will fake scrolling. This also checks if we have reached the maxScrollLeft which is some value that once we have scrolled past we will use to setIsPinned to false, and kill/disable the trigger. The reason I had to do this is because otherwise I will never reach the end since all I will be doing is adding to scrollLeft, the actual mouse scroll event is still disabled. Now we exit this pin but this still has problems. Firstly since we kill or disable it, it will reset which looks bad going back up. Furthermore, you cant reactivate it backwards. Additionally, it is still wobbly if I scroll into this section very fast before the actual pin takes effect. I'm not sure if killing it is the best thing but the entire code I have right now is starting to like my shoelaces back in kindergarten. This solution is the best I can think of right now, perhaps to introduce reverse scrolling I would use isScrollingDown and then use a seperate reverse ScrollTrigger but...... Yeah Im struggling hahah and I dont really like spaghettiness of the code right now....
It is making me rethink the design of the website but it would suck to not have ScrollTrigger cause - its cool - and cool is good hahah. Perhaps the best solution is to figure out a way to build the project with global scroll. The main problem with this is that when I tried, for some reason none of the components I wrote would render as body would go above and Z indexes didn't do anything, probably something related to how Next works that I dont understand....
Anyhow, again, thank you so much to whomever takes the time to help figure this out, I tried to describe the situation as best as I could but it is quite messy and at some point I begin to yap.... 💀 hh, anyways, if anything requires further clarification then I would be happy to help and provide that!~