Jump to content
Search Community

Scrolltrigger: Background sticky until pin, then fade / relative

inzn test
Moderator Tag

Recommended Posts

Hey, I'm relatively new to GSAP / Scrolltrigger, but I have a demo of what I kind of would like to have here:



Basically, I want to have my hero video sticky until the last text box. Then, the text box should pin while the video fades out and “unsticks”. Currently, this is quite buggy and certainly not done correctly.


let text = document.querySelectorAll(".text");

      trigger: text[text.length - 1],
      pin: true,
      start: "top center-=" + 200,
      end: "+=" + 500,
      markers: true,

    gsap.to(".main .hero", {
      opacity: 0,
      scrollTrigger: {
        trigger: text[text.length - 1],
        start: "top center-=" + 200,
        end: "+=" + 500,
        scrub: 0.5,


As you can see, the sticky part works (video is set to position: sticky) and the fading part works as well. However, the pinned text now goes over some other text (and scrolling is a bit jumpy), which is not what I want to achieve. It should stay at its position and push all following elements down until the video is gone. 


Apologies in advance for the amateur question, I hope someone here might point me in the right direction!



Link to comment
Share on other sites

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/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 


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

Link to comment
Share on other sites

I've seen the link to the site, but we can't debug a live site, could you post a minimal demo (not including all your code), but just the things that are buggy. 


As a general tip the less ScrollTriggers you can get a way with the better. A ScrollTrigger can animate a whole timeline, so if you can get away with just using one ScrollTrigger it will be a lot easier to manage!


Looking forward to your demo. I have the feeling it is an easy fix, but debugging a live site is beyond the scope of this forum (and kinda impossible)

  • Like 1
Link to comment
Share on other sites

I don't know what is happing on code sandbox, but anything I do in it result in it recompiling for 10 minutes, so I can't debug anything.


What I can see from your code is that you have several ScrollTriggers and some of them are on the same trigger `trigger: text[text.length - 1]`. This is not something I would do unless you have a specific plan, so try using as few ScrollTriggers as you can.


You are also animating several properties that are not performant width: mainWidth, height: mainHeight, marginTop: margin, these properties all require bowser repaints, better values too animate would be scaleX, scaleY, x or xPercent.


Normally the body or html is the scrollable element, but you're scrolling the main, I've never used that before, so be sure to know what you are doing. 


At the moment you have a ScrollTrigger on `trigger: ".main .hero",`, but you're also animating the same element. It is only with an opacity, but I like to stay away from animating elements that are also the trigger for my element, because if you move them while animating ScrollTrigger will have a hard time keeping up.


Beside to read the following post "Most Common GSAP Mistakes"


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