Answer the question
In order to leave comments, you need to log in
JS alternative to media query?
instead of a media query, it is quite possible to check the screen size on js and connect the desired style
, it seems to me that this is quite a good alternative -
this is how imperative programming is used instead of declarative
and the result is the same
how often is this method used in nature?
what are the disadvantages of this method?
if (window.matchMedia("(min-width: 400px)").matches) {
/* the viewport is at least 400 pixels wide */
} else {
/* the viewport is less than 400 pixels wide */
}
Answer the question
In order to leave comments, you need to log in
The best practice is NOT to use JS if it is possible to implement this functionality with CSS. The performance of CSS is many times higher than JS.
You can also set media qveri in JS. But in general, nothing prevents stupidly looking at the width of the window.
this is how imperative programming is used instead of declarativeHere is your disadvantage.
how often is this method used in nature?Only when there is no other way out.
how often is this method used in nature?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question