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

Show parent comments

-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

6

u/[deleted] Aug 22 '18

You might hide things in a menu on a small screen or add cascading chevrons.

2

u/amejin Aug 22 '18

All controllable through css. Unless you're saying dynamic elements added would be different. I that case, you kinda have an argument... But to me that is indicative of odd design and user experience/expectations. However, sometimes you just didn't have a choice... :\

2

u/Treolioe Aug 22 '18

There’s a consensus in the UX community that less information should be displayed on smaller devices. You seem to only consider the separation of concerns ”codewise” in your statement but this thinking is no longer the norm on the web. I would probably mainly use this to prevent rendering of features that are not feasible for the viewport.