Jump to content
Search Community

Dynamic variables for ScrollTrigger.matchMedia values - way to update on screen resize?

DannyAgent test
Moderator Tag

Recommended Posts

Hi,

 

I've been using ScrollTrigger.matchMedia and wanted to pass in a dynamic variable for the media values. Example below.

[`(min-height:${footer.offsetHeight)`]: function(){

},

This seems to work fine initially but starts to go wrong when resizing the screen.

 

My question is, is there a way to update the dynamic value of the matchMedia query when a screen is resized or are these values set on load? I have a custom window resize event listener where I initiate ScrollTrigger.refresh() manually, which works as intended for the associated triggers with invalidateOnRefresh. Would be great to find out if there is something similar for matchMedia.

Link to comment
Share on other sites

I'm a bit confused - are you saying that footer.offsetHeight changes and therefore you want to stop listening for that particular media query and start listening to a new one whenever that element's height changes? If so, no, you'd need to manually handle that with your own window.matchMedia() that you stop listening to and create another one and start listening to that one. Browsers don't accommodate dynamic, constantly-changing media queries like that. 

Link to comment
Share on other sites

Depending on your actual use case it might be a good idea to set css-custom-properties to new values in you media-queries and use those in your css structure. That way you might only need to update I resize when an animation is running.  

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