Last active
July 6, 2021 15:33
-
-
Save elliottmangham/0d07d58581d88b5cef14c92e52b9cf63 to your computer and use it in GitHub Desktop.
JS / Utilities / window.matchMedia (media queries)
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
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