matchMedia polyfill for testing media queries in JS
JavaScript HTML
Latest commit 2c221d5 Sep 2, 2016 @paulirish committed on GitHub Merge pull request #74 from kellyselden/npmignore
add .npmignore


matchMedia() polyfill

test whether a CSS media type or media query applies

How about resizing the browser?

Paul Hayes tackled this using CSS transitions and their transitionEnd event

His code: -- though currently it doesnt support IE6-9, since they dont have transitions, obviously. :)


test 'tv' media type

if (matchMedia('tv').matches) {
  // tv media type supported

test a mobile device media query

if (matchMedia('only screen and (max-width: 480px)').matches) {
  // smartphone/iphone... maybe run some small-screen related dom scripting?

test landscape orientation

if (matchMedia('all and (orientation:landscape)').matches) {
  // probably tablet in widescreen view

Used in: