aarongarciah
6/18/2015 - 1:37 PM

Importing CSS Breakpoints Into Javascript by @mikeherchel

Importing CSS Breakpoints Into Javascript by @mikeherchel

body:before {
  content: "smartphone";
  display: none; /* Prevent from displaying. */
}
@media (min-width: 700px) {
  body:before {
    content: "tablet";
  }
}
@media (min-width: 1100px) {
  body:before {
    content: "desktop";
  }
}
var breakpoint = {};
breakpoint.refreshValue = function () {
    this.value = window.getComputedStyle(
      document.querySelector('body'), ':before'
    ).getPropertyValue('content').replace(/\"/g, '');
  };
$(window).resize(function () {
  breakpoint.refreshValue();
  $('.breakpoint').html(breakpoint.value);
}).resize();

// Use
if (breakpoint.value == 'tablet') {
  console.log('Tablet breakpoint');
}
else {
  console.log('Some other breakpoint');
}