Skip to content

Instantly share code, notes, and snippets.

@niallobrien
Created August 21, 2014 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niallobrien/c33ff0b284f78006f924 to your computer and use it in GitHub Desktop.
Save niallobrien/c33ff0b284f78006f924 to your computer and use it in GitHub Desktop.
Execute JS based on the current screen-size (Foundation's media queries)
var mediaStateContainer = document.querySelector('.mq'),
mediaState = window.getComputedStyle(mediaStateContainer, ':before').getPropertyValue('content');
if (mediaState === 'small' ) {
// JS to run when we're on mobile.
}
.mq {
&:before {
content: 'small';
position: absolute;
display: none;
width: 0;
height: 0;
}
}
@media #{$medium-up} {
.mq:before {
content: 'medium';
}
}
@media #{$large-up} {
.mq:before {
content: 'large';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment