Skip to content

Instantly share code, notes, and snippets.

@robtarr
Created March 26, 2012 14:01
Show Gist options
  • Save robtarr/2205277 to your computer and use it in GitHub Desktop.
Save robtarr/2205277 to your computer and use it in GitHub Desktop.
mediaCheck.js
var mediaCheck = function(options) {
var mq,
matchMedia = window.matchMedia !== undefined;
if (matchMedia) {
mqChange = function(mq, options) {
if (mq.matches) {
options.entry();
} else {
options.exit();
}
};
createListener = function(mqDetails) {
mq = window.matchMedia(mqDetails.media);
mq.addListener(function() {
mqChange(mq, mqDetails);
});
mqChange(mq, mqDetails);
};
createListener(options);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment