Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save achudars/5520307 to your computer and use it in GitHub Desktop.
Save achudars/5520307 to your computer and use it in GitHub Desktop.
Breakpoints for responsive design for CSS using JavaScript
function isBreakPoint(bp) {
// The breakpoints that you set in your css
var bps = [320, 480, 768, 1024];
var w = $(window).width();
var min, max;
for (var i = 0, l = bps.length; i < l; i++) {
if (bps[i] === bp) {
min = bps[i-1] || 0;
max = bps[i];
break;
}
}
return w > min && w <= max;
}
// Usage:
if ( isBreakPoint(320) ) {
// breakpoint at 320 or less
}
if ( isBreakPoint(480) ) {
// breakpoint between 320 and 480
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment