Skip to content

Instantly share code, notes, and snippets.

@trevor-atlas
Last active October 10, 2017 15:19
Show Gist options
  • Save trevor-atlas/6eef1a2ff615a4d3c350ca846ed405de to your computer and use it in GitHub Desktop.
Save trevor-atlas/6eef1a2ff615a4d3c350ca846ed405de to your computer and use it in GitHub Desktop.
get current media query size from HTML::before
/**
* 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