Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
deJardine

Scroll Trigger, with child position:sticky element

Recommended Posts

Hi there,

This might be an edge case, but I'm trying to create a position:sticky element inside a scrolltrigger. It seems to incorrectly stick the position the "Sticky Bar" div as the parent uses a translate to pin the scrollTrigger (which affects the position of the sticky bar).

Are there any workarounds for this type of setup?

 

 

See the Pen BaZgWOj by grafiknz (@grafiknz) on CodePen

Link to comment
Share on other sites

It is definitely an edge case where position: sticky just won't work but you could use ScrollTrigger to create a similar effect (if I understand your goal correctly): 

See the Pen gORNVoN?editors=0010 by GreenSock (@GreenSock) on CodePen

 

Does that help? 

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

Thanks, great! that solves it (had no idea you could nest scrolltriggers!) could I also use pinReparent ?

Link to comment
Share on other sites

Why would you want to use pinReparent? It's only intended as a last resort in some very tricky situations, but I'd recommend avoiding it if you can because it's expensive and tricky. 

Link to comment
Share on other sites

@GreenSock I am trying to the same thing, but without any content between the sticky and the curtain. I've adjusted your example here, 

See the Pen YzxXZgx by joris-rotteveel (@joris-rotteveel) on CodePen

. Unfortunately, the black box scrolls down when scrolling before pinning. 

 

Is this possible you think?

Link to comment
Share on other sites

You really can't have two nested pinned elements simultaneously. In other words, you're trying to pin an element whose ancestor is also simultaneously pinned. You could just tell that nested element's ScrollTrigger to start when the ancestor's is finished. In this case, it's simple because we can use the .previous() method to grab that ScrollTrigger and use its end:

start: self => self.previous().end

See the Pen GRvJezp?editors=0010 by GreenSock (@GreenSock) on CodePen

 

Is that what you're looking for? 

  • Thanks 2
Link to comment
Share on other sites

@GreenSock So the order of creation would be important here. This is definitely  a great new way of dealing with it! Will look into the docs and dig a bit deeper. Thanks a million for your help. This is why I have absolutely no issues with paying for a subscription to GSAP, great product and awesome forum! 

  • Like 1
  • Thanks 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.
×