Jump to content
Search Community

I've been trying to create a simple pin on ScrollTrigger, but I've no idea what I'm doing wrong.

johndoe000 test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

I'm trying to do is replicate something like 

See the Pen YzXdbQo?editors=1010 by GreenSock (@GreenSock) on CodePen

. instead of the content, the whole section gets pinned. But in my case, the last (third) child, doesn't make space for the footer even though pinSpacing is false. Also, 

when the child-3 almost covers the child-2, if I scroll futher, the child-3 is pushed down a little bit and only on further scrolling covers the child-2. See the picture below, child 3 is almost covering it. And then I scroll further, look at the second picture.Screenshot2024-01-16114726.thumb.png.b1f171f61e1d38842308f973072e60fe.pngScreenshot2024-01-16114745.thumb.png.d66f9789c2dc6e8d62a776833423cae2.png

 

 

See the Pen ExMZxBN?editors=1010 by green_viper (@green_viper) on CodePen

Link to comment
Share on other sites

Ah, that's a CSS issue - you've got leaking/collapsing margins. The <h1> has a rather large margin on it by default, and you've got that at the very top of a container <div> that has no padding whatsoever, and no border, thus the margin on that <h1> "leaks" outside the bounds. Then, when it gets pinned, it suddenly gets contained so that it can't "leak" out anymore. 

 

One simple solution is to add a small padding-top on the container, like 1px. Or remove the margin on your leaking element(s). Or use a 1px transparent border. Or anything that'll prevent that margin from leaking outside the container. 

 

See the Pen jOJyeym by GreenSock (@GreenSock) on CodePen

 

Does that help? 

Link to comment
Share on other sites

I went

*, *::after, *::before{

  margin: 0;

  padding: 0;

  box-sizing: border-box;

}

 

and the second issue seems to have been resolved. Thank you very much for that. But the footer still remains covered by the third child.

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