Jump to content
Search Community

Scroll Trigger doesn't maintain correct state when resizing elements with position sticky

Bonsai test
Moderator Tag

Recommended Posts

I'm running into a resize issue with a slideshow animation I'm working on. When the browser resizes, all the animations are reset to the beginning (see https://ugm-staging.azurewebsites.net/). I've also attached a codepen that shows some of the weirdness I run into. It scales the font size up, but on resize the font size is reset even though it's still scrolled to the same point. Not necessarily unexpected, since my use of overflow hidden is likely throwing a wrench in how scroll trigger handles resizing. Unfortunately, that's required to ensure the slideshow works as expected on mobile devices, as things break when the address bar appears/disappears on them. I've confirmed that scrollTop is unchanged after the animation resets, so it seems that greensock isn't facturing that in for some reason. My idea right now is modify the refresh logic to fix whatever is knocking things out of position, but I'm not sure how best to go about this. Any suggestions would be much appreciated.

See the Pen MWjXdJx by jaandrews (@jaandrews) on CodePen

Link to comment
Share on other sites

15 hours ago, Bonsai said:

my use of overflow hidden is likely throwing a wrench in how scroll trigger handles resizing

Yeah, that's definitely the cause of the issue. 

 

If I were you I would try to fix whatever "breaks" when the address bar appears/disappears. We don't recommend scroll-jacking and what you're doing definitely is scroll-jacking. But if you are going to scroll-jack it likely doesn't make much sense to use ScrollTrigger at all, it'd likely work better with regular tweens/timelines without ScrollTrigger.

Link to comment
Share on other sites

Yeah, I'm not a fan of scroll jacking either, but it was a requirement of the project unfortunately. Would have preferred to use Scroll Trigger's snapping capabilities. I might be able to hack my way around this issue by recording the progress of each timeline with the refreshInit event and restoring it in the refresh event. I did try this earlier without success, but I might have missed something. I think the scroll trigger was overriding the progress value I set after the refresh event. See below for the basic gist of what I tried before.

var progress;
var tl = gsap.timeline({ scrollTrigger: { ... }});
ScrollTrigger.addEventListener('refreshInit', () => {
  progress = tl.progress;
});
ScrollTrigger.addEventListener('refresh', () => {
  tl.progress(progress);
});

Any suggestions on what tweaks I should make to this logic to make this work, if any? It's a hack for sure, but I'm trying to avoid the need to rework the entire animation.

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