matchmedia-polyfill
matchMedia polyfill for testing media queries in JS
Last updated 8 years ago by paulirish .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install matchmedia-polyfill 
SYNC missed versions from official npm registry.

npm

matchMedia() polyfill

test whether a CSS media type or media query applies

Usage

// Likely want to requier both polyfills..
require('matchmedia-polyfill');
require('matchmedia-polyfill/matchMedia.addListener');

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:

How about resizing the browser?

Paul Hayes tackled this using CSS transitions and their transitionEnd event

His code: https://github.com/fofr/matchMedia.js -- though currently it doesnt support IE6-9, since they dont have transitions, obviously. :)


Current Tags

  • 0.3.2                                ...           latest (8 years ago)

3 Versions

  • 0.3.2                                ...           8 years ago
  • 0.3.1                                ...           8 years ago
  • 0.3.0                                ...           11 years ago
Maintainers (2)
Downloads
Total 10
Today 0
This Week 0
This Month 9
Last Day 0
Last Week 8
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE