Jump to content


MatchMedia & Timeline placement

Moderator Tag

Recommended Posts

Had a trawl through the site and codepen but couldn't find an answer.


I have timelines that require different scrolltrigger values according to media queries, is it correct to place paused timelines outside the ScrollTrigger.matchMedia() and the scrolltrigger/s inside the function? Or is it best practice to duplicate timelines in each media query? Or some other setup?



See the Pen QWNrJRr by brodiero (@brodiero) on CodePen

Link to comment
Share on other sites

There isn't a hard-and-fast rule about this, but I'd personally find it more readable/maintainable to put stuff inside the matchMedia() object. Remember that it'll keep track of the ScrollTriggers that are created inside that function and kill those (along with their attached animation) when the media query no longer matches. 


Let us know if you run into any problems. 🙌

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thanks Jack, it's good to know it's acceptable, if not recommended 😉


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