Last active
September 20, 2019 09:54
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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