• Stars
    star
    318
  • Rank 131,872 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 12 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Test css media queries in javascript. A faster polyfill for matchMedia support. Follow the project on Twitter @mediamatchjs.

Media.match

Test css media queries in javascript. A faster polyfill for matchMedia support. Follow the project on Twitter @mediamatchjs.

Why?

Media type and feature support

  • type: all, screen, print, speech, projection, handheld, tv, braille, embossed, tty
  • width: width, min-width, max-width
  • height: height, min-height, max-height
  • device-width: device-width, min-device-width, max-device-width
  • device-height: device-height, min-device-height, max-device-height
  • aspect-ratio: aspect-ratio, min-aspect-ratio, max-aspect-ratio
  • device-aspect-ratio: device-aspect-ratio, min-device-aspect-ratio, max-device-aspect-ratio
  • orientation: orientation
  • resolution: resolution, min-resolution, max-resolution
  • device-pixel-ratio: device-pixel-ratio, min-device-pixel-ratio, max-device-pixel-ratio
  • color: color, min-color, max-color
  • color-index: color-index, min-color-index, max-color-index

Lacks support

  • monochrome: monochrome, min-monochrome, max-monochrome
  • scan: scan
  • grid: grid

Requirements

media.match.min.js/media.match.js

  • Provides core functionality. Does not contain external javascript library or css dependencies.
  • Version 1 of this project contained a css dependency that is now solely handled by media.match.js. See branch, "version1" for previous iteration.

Example

Both code blocks are valid uses of matchMedia(). The first example shows the caching of a MediaQueryList object and the second shows an alternative usage as well as addListener support. The addListener method is part of the MediaQueryList object, therefore it can be added on the cached version or immediately after matchMedia().

<script type="text/javascript">
    var mql = window.matchMedia('screen and (color) and (orientation: landscape) and (min-width: 600px) and (min-height: 400px)');
    //console.log(mql);
    /*
        mql has the following properties:
        matches         : <Boolean>
        media           : <String>
        addListener     : <Function>
        removeListener  : <Function>
    */
</script>
<script type="text/javascript">
    window.matchMedia('screen and (min-width: 600px) and (min-height: 400px), screen and (min-height: 400px)')
        .addListener(function(mql) {
            if (mql.matches) {
                // Media query does match
            } else {
                // Media query does not match anymore
            }
        });
</script>

Related projects

  • Nonresponsive: Media queries for the unsupportive IE6-8.
  • Picture: Responsive images based on the 'picture' element proposal.
  • Img-srcset: Responsive images based on the 'srcset' attribute proposal.

More Repositories

1

jquery-parallax

Parallax jQuery plugin
JavaScript
67
star
2

img-srcset

Responsive images based on the 'srcset' attribute proposal. Lightweight, no nonsense, all browser supporting, fast polyfill for img srcset.
JavaScript
50
star
3

picture

Responsive images based on the 'picture' element proposal. See http://picture.responsiveimages.org/.
JavaScript
47
star
4

jquery-columnlist

jQuery plugin for splitting up uls into equal lists
JavaScript
15
star
5

jquery-threesixty

A jQuery plugin for 360 image rotations
JavaScript
13
star
6

nonresponsive

CSS 3 media queries for the unsupportive (IE 6-8). Support more features with greater speed
JavaScript
10
star
7

jquery-divider

A jQuery plugin for a sliding image divider
JavaScript
10
star
8

jquery-imageready

A jQuery plugin for a bulk image load event
JavaScript
9
star
9

jquery-big-image

A plugin for hover image zooming that doesn't suck.
8
star
10

pointbreak.js

PointBreak provides a friendly interface to matchMedia with named media queries and easy to create callbacks
JavaScript
8
star
11

jumpcloud-sys-tool

Go binary for configuring systems with the JumpCloud SystemContext API
Go
5
star
12

mkcertchain

Generate an optimal intermediate SSL certificate chain
Perl
3
star
13

homebrew-formulas

Ruby
3
star
14

scss-style-guide

The WebLinc SCSS Style Guide
2
star
15

snippets

A collection of useful text editor snippets for working with the WebLinc platform
2
star
16

modcon

JavaScript Modular Framework & Execution Controller
JavaScript
2
star
17

linc

js execution controller
CoffeeScript
2
star
18

airbrake-notifier.js

Client-side error notifier for Airbrake/Hoptoad
JavaScript
1
star
19

actionview-pathfinder

Ruby
1
star
20

foodcritic-junit

Parses foodcritic output in to JUnit format
Ruby
1
star
21

pseudoL10N

A script to translate your site into a pseudo localization language for front-end testing.
JavaScript
1
star