r/javascript • • Aug 21 '18

Effectively supported in all browsers, JavaScript has its own form of media queries just like CSS.

https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
465 Upvotes

114 comments sorted by

View all comments

32

u/MayorMonty Aug 21 '18 edited Aug 22 '18

Huh, TIL. And to think I've been using resize events for all these years now...

Edit: scroll events are different

1

u/BONUSBOX _=O=>_();_() Aug 22 '18

matchMedia can still be combined with resize if you want components and functionality to adapt to a changing screen size or orientation. def simplifies things in any case...