Skip to content

Instantly share code, notes, and snippets.

@pixelhijack
Last active August 29, 2015 14:02
Show Gist options
  • Save pixelhijack/298d387778dee7138911 to your computer and use it in GitHub Desktop.
Save pixelhijack/298d387778dee7138911 to your computer and use it in GitHub Desktop.
//==============================
//JAVASCRIPT @MEDIA QUERIES
//================================
var widthMax832px = window.matchMedia('(max-width: 832px)');
console.log('widthMax832px: ', widthMax832px);
//always check if window.matchMedia exist (older IE can crash on this. If still needed, use Paul Irish polyfill)
if(window.matchMedia && window.matchMedia("(max-width: 1201px)").matches) {
console.log('js:@media: width of browser: less then 1201px');
} else {
console.log('js:@media: width of browser: more then 1201px');
};
widthMax832px.addListener(function(changed) {
if(changed.matches) {
console.log('js:@media: width of browser: CHANGED TO less then 832px');
} else {
console.log('js:@media: width of browser: CHANGED TO more then 832px');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment