Jump to content
Search Community

ScrollTrigger and resizing window

BarheimCoder test
Moderator Tag

Go to solution Solved by akapowl,

Recommended Posts

I've created a pen to test this. I'm trying to run a different timeline if the screensize reaches a certain breakpoint. As of now it works well on load, but resizing the window creates a few issues:

  • The background color I set up to test works, but it overlaps
  • The lottie animation freezes

 

I think when resizing the window there should be something to rebuild the timeline and clear of the content of the old one, but so far nothing I've tried really worked but there seems to be many things that could fix this like .kill, .clear or invalidateOnRefresh for scrolltrigger.

 

Any advice is very welcome. Thanks in advance

See the Pen YzQjbVP by barheimcoder (@barheimcoder) on CodePen

Link to comment
Share on other sites

  • Solution

Hey there @BarheimCoder

 

1 hour ago, BarheimCoder said:

I think when resizing the window there should be something to rebuild the timeline and clear of the content of the old one

 

There is; what you are looking for is ScrollTrigger.matchMedia() - it will handle that work for you.

 

That could maybe look something like this in your case. Hope it helps.

 

See the Pen f02baa4689f87ef6259e344afd8f50b1 by akapowl (@akapowl) on CodePen

 

 

Edit:

 

And if there isn't that much you want to change for different screensizes, as is the case in your demo, you can of course reduce your code down a bit by using a function with different parameters passed to create your ScrollTriggers for different viewports.

 

 

See the Pen 5e46300a8c764b6b39437281be6ebd8c by akapowl (@akapowl) on CodePen

 

 

  • Like 2
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...