matchMedia polyfill for testing media queries in JS
npm install @txhawks/matchmedia-polyfill
> This fork of the matchMedia polyfill was created for the sole reason of
publishing the latest version to npm (see issue #82
in the original repository). It will be deprecated once the issue is resolved.
* Authors: Scott Jehl, Paul Irish, Nicholas Zakas
* Spec: dev.w3.org/csswg/cssom-view/#dom-window-matchmedia
* Native support: Chrome since m10, Firefox since 6, and Safari since 5.1
His code: https://github.com/fofr/matchMedia.js -- though currently it doesnt support IE6-9, since they dont have transitions, obviously. :)
#### test 'tv' media type
``js`
if (matchMedia('tv').matches) {
// tv media type supported
}
js
if (matchMedia('only screen and (max-width: 480px)').matches) {
// smartphone/iphone... maybe run some small-screen related dom scripting?
}
`#### test landscape orientation
`js
if (matchMedia('all and (orientation:landscape)').matches) {
// probably tablet in widescreen view
}
``