Skip to content

Instantly share code, notes, and snippets.

@kruzyk
Last active September 20, 2019 09:54
Show Gist options
  • Save kruzyk/da3f62d1f0e9c13b91b341402f30ffd9 to your computer and use it in GitHub Desktop.
Save kruzyk/da3f62d1f0e9c13b91b341402f30ffd9 to your computer and use it in GitHub Desktop.
adjust the appearance and behavior depending on the width of the screen (CSS media queries in JS)
function handleProperDevice(x) {
if (x.matches) {
// If media query matches
} else {
// If media query doesn't match
}
}
var x = window.matchMedia("(max-width: 768px)");
handleProperDevice(x); // Call listener function at run time
x.addListener(handleProperDevice); // Attach listener function on state changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment