Skip to content

Instantly share code, notes, and snippets.

@andreyshr
Last active September 21, 2018 09:47
Show Gist options
  • Select an option

  • Save andreyshr/02029de5a11c795de3e0ad9612311069 to your computer and use it in GitHub Desktop.

Select an option

Save andreyshr/02029de5a11c795de3e0ad9612311069 to your computer and use it in GitHub Desktop.
MediaQueries
// media query event handler
if (matchMedia) {
const 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