Created
February 25, 2017 19:33
-
-
Save Nifled/31b0e1de5c2ce72a1091d306f0a1cac0 to your computer and use it in GitHub Desktop.
Javascript Media Queries (with listener)
This file contains hidden or 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
/* JavaScript Media Queries */ | |
if (matchMedia) { | |
var mq = window.matchMedia("(min-width: 1200px)"); | |
mq.addListener(WidthChange); | |
WidthChange(mq); | |
} | |
// media query change | |
function WidthChange(mq) { | |
var msg = (mq.matches ? "more" : "less") + " than 1200px pixels"; | |
if (mq.matches) { | |
document.getElementById("owner").style.border = "1px solid black"; | |
} else { | |
document.getElementById("owner").style.border = "3px solid green"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment