Created
January 28, 2015 16:13
-
-
Save BracketBulldog/87264a6705348f7fdf79 to your computer and use it in GitHub Desktop.
Ultra compact Bootstrap breakpoint detection with jQuery (Dirty)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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