Skip to content

Instantly share code, notes, and snippets.

@elliottmangham
Last active July 6, 2021 15:33
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 elliottmangham/0d07d58581d88b5cef14c92e52b9cf63 to your computer and use it in GitHub Desktop.
Save elliottmangham/0d07d58581d88b5cef14c92e52b9cf63 to your computer and use it in GitHub Desktop.
JS / Utilities / window.matchMedia (media queries)
if (matchMedia) {
const mq = window.matchMedia("(min-width: 800px)");
mq.addListener(WidthChange);
WidthChange(mq);
}
// media query change
function WidthChange(mq) {
if (mq.matches) {
console.log( 'window width is at least 800px' );
} else {
console.log( 'window width is less than 800px' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment