@txhawks/matchmedia-polyfill

0.3.0 • Public • Published

npm

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.

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: https://github.com/fofr/matchMedia.js -- though currently it doesnt support IE6-9, since they dont have transitions, obviously. :)

Usage

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:

Readme

Keywords

none

Package Sidebar

Install

npm i @txhawks/matchmedia-polyfill

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

7.83 kB

Total Files

6

Last publish

Collaborators

  • txhawks