var wmq = window.matchMedia("(min-width: 400px)"); if (wmq.matches) { /* the view port is at least 400 pixels wide */ } else { /* the view port is less than 400 pixels wide */ } |
Event listener:
wmq.addListener(function(wmq) { console.log(wmq.media + " " + (wmq.matches ? 'matches' : "doesn't match")); }); |
Suppored in all browsers. (IE10+)