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

-9

u/amejin Aug 22 '18

I mean.. Neat.. I guess? For those weird times you want a button to launch a modal instead of a menu?

Im pretty sure this is Microsoft's doing as a means to provide app functionality for multiple devices that run on JS as an engine instead of C#

5

u/[deleted] Aug 22 '18

Responsive design?

-3

u/amejin Aug 22 '18 edited Aug 22 '18

Im not sure your script should behave differently than intended just because the window size changes.

As I learned it, layout, in majority, should be handled by css. Script is for data and state, and fringe cases where css cant meet the need or is not optimal or performant.

Maybe its my limited vision, but Im not sure this would be the thing I run to when thinking about how a page will look and feel on different devices. A menu button should continue to display a menu. The menu layout and design can be controlled with media queries already and the script should have nothing to do with it (in my very humble opinion).

Now - we all know in programming there are always multiple avenues to solve a problem. If this solves yours, feel free to use it. :)

Edit: punctuation, a word

1

u/dzkn Aug 22 '18

This is absolutely golden for React/Vue etc. You can render one component on desktop and one on mobile for example.