Created
March 17, 2014 09:13
-
-
Save c3ry5/9596169 to your computer and use it in GitHub Desktop.
How to get the media query of your page
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
body #currentMediaQuery { | |
display: none; | |
} | |
@media only screen and max-width 479px { | |
body #currentMediaQuery { | |
font-family: xxs; | |
} | |
} | |
@media only screen and min-width 480px { | |
body #currentMediaQuery { | |
font-family: xs; | |
} | |
} | |
@media only screen and min-width 768px { | |
body #currentMediaQuery { | |
font-family: sm; | |
} | |
} | |
@media only screen and min-width 992px { | |
body #currentMediaQuery { | |
font-family: md; | |
} | |
} | |
@media only screen and min-width 1310px { | |
body #currentMediaQuery { | |
font-family: lg; | |
} | |
} |
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
var getMediaQuery = function () { | |
var id = "currentMediaQuery", | |
elem, state, div; | |
if(!document.getElementById(id)) { | |
div = document.createElement("div"); | |
div.id = id; | |
document.body.appendChild(div); | |
} | |
elem = document.getElementById(id); | |
if (elem.currentStyle) { | |
state = elem.currentStyle.fontFamily; | |
} else if (window.getComputedStyle) { | |
state = window.getComputedStyle(elem).getPropertyValue("font-family"); | |
} | |
return state; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment