Last active
October 10, 2017 15:19
-
-
Save trevor-atlas/6eef1a2ff615a4d3c350ca846ed405de to your computer and use it in GitHub Desktop.
get current media query size from HTML::before
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
/** | |
* check the html::before element for a string indicating the currect css media query. | |
* @return boolean if the passed string matches the current media query contained in the ::before's content attribute. | |
* In your css just add a content value to the html::before element that you can check for a size. | |
* E.G: if (MQ('large')) { ...do stuff } | |
*/ | |
const MQ = (MQName: string): boolean => { | |
return MQName === window | |
.getComputedStyle(document.documentElement, '::before') | |
.getPropertyValue('content') | |
.replace(/['"]/g, ''); | |
} | |
export default MQ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment