Skip to content

Instantly share code, notes, and snippets.

@aarongarciah
Last active August 29, 2015 14:23
Show Gist options
  • Save aarongarciah/bb8817f8cfe6ea327675 to your computer and use it in GitHub Desktop.
Save aarongarciah/bb8817f8cfe6ea327675 to your computer and use it in GitHub Desktop.
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');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment