Skip to content

Instantly share code, notes, and snippets.

@omariosouto
Created November 12, 2015 11:35
Show Gist options
  • Save omariosouto/5cb7f7ef5190794a2bd5 to your computer and use it in GitHub Desktop.
Save omariosouto/5cb7f7ef5190794a2bd5 to your computer and use it in GitHub Desktop.
(function (window, document, undefined) {
'use strict';
// Initialize the media query
var mediaQuery = window.matchMedia('(min-width: 560px)');
// Add a listen event
mediaQuery.addListener(doSomething);
// Function to do something with the media query
function doSomething(mediaQuery) {
if (mediaQuery.matches) {
document.body.style.backgroundColor = 'CornflowerBlue';
} else {
document.body.style.backgroundColor = 'FireBrick';
}
}
// On load
doSomething(mediaQuery);
// Modernizr
//window.addEventListener('resize', function() {
// if (Modernizr.mq('(min-width: 560px)')) {
// document.body.style.backgroundColor = 'CornflowerBlue';
// } else {
// document.body.style.backgroundColor = 'FireBrick';
// }
//}, false);
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment