Jump to content
Search Community

Dynamic startvalue for ScrollTrigger

niklasinla test
Moderator Tag

Go to solution Solved by akapowl,

Recommended Posts

Hi!
I'm trying to have dynamic value as a startvalue for the the scroll.

I've tried the code below and that's not working...

        let header = document.getElementById("header");
        let headh = header.getBoundingClientRect();
        let headheight = headh.height;            
            
        gsap.to("#header", {
            scrollTrigger: {
                trigger: "#aboutus",
                start: "top headheight",
                end: "top bottom",
                toggleActions: "play none reverse none",
                markers: true
            },
            backgroundColor: "#FFFFFF",
            duration: 0.1
        });

So I need to have the start value of the scroller to be the height of the header but the header will change it's height depending on the screensize.

When I looked at the tutorial-video for ScrollTrigger I found out about this way of doing it:

() => "+=" + document.querySelector("header").offsetHeight But how do I combine this with having the "trigger" still set to be triggered at the "top"?
I can't figure that one out...

Best, Niklas

Link to comment
Share on other sites

Hi!
Thanks for the suggestions!!
Hmm...neither of them are working for me.
I've made a demo on Codepen.
Now I've set a fixed startvalue in pixels for the scroller - the same value as the height of the header.
That works exactly the way I want which is that the header has a transparent background and then the background-color animates in when the header "catches up" with the content.

But as described earlier I would like the startvalue to be dynamic....

See the Pen ExyeRvo by WideCircle (@WideCircle) on CodePen

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