Created
July 15, 2018 11:20
-
-
Save mishalrai/f22230329700c18eb86581098709bf9a to your computer and use it in GitHub Desktop.
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 myFunction(x) { | |
if (x.matches) { // If media query matches | |
document.body.style.backgroundColor = "yellow"; | |
console.log('one time only'); | |
} else { | |
document.body.style.backgroundColor = "pink"; | |
console.log('pink'); | |
} | |
} | |
var x = window.matchMedia("(max-width: 700px)") | |
myFunction(x) // Call listener function at run time | |
x.addListener(myFunction) // Attach listener function on state changes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment