Skip to content

Instantly share code, notes, and snippets.

@krabello
Created June 25, 2015 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krabello/389935ea0bac297011e7 to your computer and use it in GitHub Desktop.
Save krabello/389935ea0bac297011e7 to your computer and use it in GitHub Desktop.
Javascript Media Query Event Handler
// media query event handler
if (matchMedia) {
var mq = window.matchMedia("(min-width: 500px)");
mq.addListener(WidthChange);
WidthChange(mq);
}
// media query change
function WidthChange(mq) {
if (mq.matches) {
// window width is at least 500px
}
else {
// window width is less than 500px
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment