Jump to content
Search Community

Scroll trigger pinned section with dynamic height based on content

jacopotaba test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hello, i need to do a multiple pinning sections that should have dynamic height based on the content inside. generally a section should have height from 500px to unknown because the content will be taken from the backend and can have 1 or 100 paragraphs. the problem is that if te content of the section if minor of 100vh it works, if it is more thank 100vh the section doesn't scroll. in the pen you will se only first 2 paragraphs and should be visible all of them.

i have tried also this solutions 

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

 and the scroll in the longest section (more than 100vh) is working, but the pinning logic is not correct, i need pin from top to bottom.

See the Pen PoyzmKo by jacopotabani (@jacopotabani) on CodePen

Link to comment
Share on other sites

1 hour ago, GreenSock said:

Taken from the answer to your question in another thread: is this what you're looking for?: 

 

 

the scroll behavior is correct, but if for example the first section has a height lower than 100vh, it will not start from the top of the page. how can I start sections even with height less than 100vh from the top of the page? try put height:100px on first section @GreenSock .  The yellow section should start from top of the page, but the pin-spacer is making this spaceimage.thumb.png.fd635ac7a7236c6bf3140ed3686768aa.png

 

Link to comment
Share on other sites

Hi,

 

Maybe using this achieves what you're looking for:

panels.forEach((panel, i) => {
  ScrollTrigger.create({
    trigger: panel,
    start: () => (panel.offsetHeight < window.innerHeight ? "top top" : "bottom bottom"), 
    pin: true, 
    pinSpacing: false 
  });
});

Basically check where each panel should be pinned based on it's height and the window height.

 

Here is a live example (no snapping though):

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

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

  • 2 weeks later...

Yep, if you'd like some help please make sure you provide a minimal demo that clearly shows the issue you're describing and we'd be happy to take a peek. I suspect Cassie is correct about you just needing to call ScrollTrigger.refresh() to re-calculate all the start/end values because you're shifting them around by resizing things. 

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