Skip to content

Instantly share code, notes, and snippets.

@BracketBulldog
Created January 28, 2015 16:13
Show Gist options
  • Save BracketBulldog/87264a6705348f7fdf79 to your computer and use it in GitHub Desktop.
Save BracketBulldog/87264a6705348f7fdf79 to your computer and use it in GitHub Desktop.
Ultra compact Bootstrap breakpoint detection with jQuery (Dirty)
var cw, pcw;
$(window).on('load resize', function () {
// get width as int
cw = parseInt($('.container').css('width'));
// make 'current !== previous' equation easier
if (cw < 750) {cw = 'xs';}
// execute breakpoint-specific action if the current container width is not the same as the previous one
if (cw !== pcw) {
if (cw === 'xs') {
console.log('xs');
} else if (cw === 750) {// default bs value,change if needed (and look back up a bit ;))
console.log('sm');
} else if (cw === 970) {
console.log('md');
} else if (cw === 1170) {
console.log('lg');
};
};
// current container width becomes previous one
pcw = cw;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment