Jump to content
Search Community

ScrollTrigger adding inset to element

Lovestoned test
Moderator Tag

Recommended Posts

Yeah, just for the record, when pinning ScrollTrigger has to set the top, left, right, and bottom properties in order to ensure things are locked into place properly, but the browser combines them all into an "inset" like you're seeing. That's not actually what ScrollTrigger is setting internally but functionally it's just a different way of describing the same thing. 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Hello

 

I'm having a similar problem but here the inset values created by the pin-spacer are actually breaking the design, any clues on how to remove this inset?

Here is a demo of the site https://otra-9d8f98.webflow.io/info2-copy and the elements in question are the ones in magenta border

 

image.png.27c6789d62ac09f2b071bbf07aae34e9.png

 

this is the JS code being used and in the bottom some images from the inspect

 

<script>
	gsap.registerPlugin(ScrollTrigger)
	  var actionContact = gsap.to('#sticky-contact', { border: 'solid 1px magenta', ease: 'none', duration: 0.25 });
	var actionServicios = gsap.to('#sticky-servicios', { border: 'solid 1px magenta', ease: 'none', duration: 0.25 });

  ScrollTrigger.create({
    trigger: ".banner-top",
    start: "bottom top",
    end: 'max',
    markers:true,
    pin: '#sticky-contact',
    pinSpacing: false,
    animation: actionContact,
    toggleActions: 'play reverse play reverse'
  });

	ScrollTrigger.create({
    trigger: ".banner-top",
    start: "bottom top",
    endTrigger: ".section-15",
    end: 'top bottom',
    markers:true,
    pin: '#sticky-servicios',
    pinSpacing: false,
    animation: actionServicios,
    toggleActions: 'play reverse play reverse'
  });

</script>

 

image.png.449c4e6d61815a1071285858ad680a87.pngimage.png.a8b6426973810d6b8012600704a3a6db.pngimage.png.fc6f6ab28e552b6b21fc87f960f6fc11.png

 

image.png

Edited by David Chavez
deleted an extra image that was not needed
Link to comment
Share on other sites

Hm, I looked at your site and it is not clear to me what you think the problem is. Can you please be very specific about what you think is supposed to happen (but isn't happening)? Why do you think "inset" is the problem? 

 

It's super difficult to troubleshoot without a minimal demo. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue in the simplest way possible? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

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

 

If you're using something like React/Next/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

Okay, sorry for not being clear, I'll try to be concise

I couldn't replicate the problem in codepen (it works as expected)

See the Pen zYaVQKJ by ATOMICHAVEZ (@ATOMICHAVEZ) on CodePen

The problem in the live site is that the two elements that have the "pin" applied get wrapped in a pin-spacer with top inset of 120px and 240px respectively. I don't understand where these insets come from, as you can see in the image below the elements get shifted downwards because of this and is not the expected behavior

 

image.thumb.png.c2d936f145d2b49076184ebe07b401ed.png

 

 

Link to comment
Share on other sites

Hm, it's pretty tough to diagnose if you can't provide a CodePen that illustrates the issue, but my guess is that you're lazy-loading an image (or something) higher up on the page so that when the page's "load" event fires and ScrollTrigger.refresh() is called (automatically), it calculates the start/end positions based on the DOM positioning at that point and then later you've got something (like an image loading) that shifts things down. 

 

Again, I'm totally guessing here. If you can provide something that's editable and reproduces the issue (hopefully in a very minimal way), that'll go a long way to getting your question answered. We'd love to help...but our hands are tied at this point.

 

Maybe try calling ScrollTrigger.refresh() when you know for sure that the DOM/layout is settled. Just to experiment (NOT a final solution), try calling it after a few seconds just to see if it resolves things: 

setTimeout(() => ScrollTrigger.refresh(), 2000);

🤷‍♂️

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