niallobrien
8/21/2014 - 9:24 AM

Execute JS based on the current screen-size (Foundation's media queries)

Execute JS based on the current screen-size (Foundation's media queries)

.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';
  }
}
var mediaStateContainer = document.querySelector('.mq'),
mediaState = window.getComputedStyle(mediaStateContainer, ':before').getPropertyValue('content');

if (mediaState === 'small' ) {
  // JS to run when we're on mobile.  
}