javascript - CSS determining active media query -


There is no direct way to determine which media query is active in javascript (not included in parsing css code is)? For example, I have two questions:

  @ media screen and (max-width: 800 px) media screen and (minimum-width: 801 px)  

/ Code>

Without parsing and viewing the client, how can I tell which of these is evaluated?

Although this is an old question, when it ranks high on googling for the problem .

is official and supported by (IE10 +) and will allow you to query certain media queries currently matching.

From the original question:

  if (window.matchMedia ('screen and (max-width: 800px)').) {Matches} // match it } And {// do not match}   

You can also listen for that query when the result of that query code is returned to that window.matchMedia again Start Ns:

  var mql = window.matchMedia ('screen and (max-width: 800px)'); Mql.addEventListener (function (mq) {if (mq.matches) {// matches it} else {// do not match}});    

Comments