Skip to content

Instantly share code, notes, and snippets.

@bjmiller121
Last active January 16, 2016 00:53
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 bjmiller121/38642be87e6c2769e1d5 to your computer and use it in GitHub Desktop.
Save bjmiller121/38642be87e6c2769e1d5 to your computer and use it in GitHub Desktop.
Breakpoint body classes
/**
* Add breakpoint classes to the body as a utility.
*
* Requires jQuery and underscore
*/
Breakpoints = {
'mobileMax': 639,
'tabletMin': 640,
'tabletMax': 960,
'desktopMin': 961
};
(function ($) {
$(document).ready(function () {
breakpointClass();
$(window).on('resize orientationchange', _.debounce(breakpointClass, 100));
});
function breakpointClass() {
var width = window.outerWidth,
$body = $('body');
// Remove any previously set breakpoint class.
$body.removeClass('breakpoint-mobile breakpoint-tablet breakpoint-desktop');
// Set breakpoint class based on window width.
if (width >= Breakpoints.desktopMin) {
$body.addClass('breakpoint-desktop');
} else if (width <= Breakpoints.mobileMax) {
$body.addClass('breakpoint-mobile');
} else {
$body.addClass('breakpoint-tablet');
}
}
})(jQuery, window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment