Jump to content
GreenSock

mfk

How do i use functions in scrollTrigger "start" option

Moderator Tag

Recommended Posts

Hello, im trying to use a function to return a dynamic number value for the  position of 'scroller-start' of my scroll trigger

 

// simplified scroll trigger here
ScrollTrigger.create({
  trigger: ".logo",
  start: "top DYNAMIC-VALUE-HERE",
  end: "+=500",
  scrub: 1,
});


// function to return dynamic value
function get_start() {
  return document.querySelector('.fixed-elements h2').offsetTop
}

 

I see that its possible to use functions in the start option, but how do use it only for the 2nd value as shown above?

Link to comment
Share on other sites

create a variable which is placed out site of the string. 

 

start: "top " + DYNAMIC-VALUE-HERE,

 

Something like this should work. 

  • Like 1
Link to comment
Share on other sites

Hey mfk and welcome to the GreenSock forums.

 

2 hours ago, mfk said:

I see that its possible to use functions in the start option, but how do use it only for the 2nd value as shown above?

As mvaneijgen said, you can concatenate the value with a string. Using your function it should look something like this:

start: "top " + get_start(),

 

  • Like 2
Link to comment
Share on other sites

thanks! that sorted it out

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