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

65

u/PortablePawnShop Aug 21 '18

Holy shit, I've been doing absurdly complicated workarounds for some of this

1

u/deadlyicon Aug 22 '18

Can’t you get everything you get from css media queries, in JS, by listening to window resize events and doing a bit of math?

6

u/dzkn Aug 22 '18

Yes, but now you don't have to