Skip to content

Instantly share code, notes, and snippets.

@cedmond
Last active March 14, 2020 16:29
Show Gist options
  • Save cedmond/8851979 to your computer and use it in GitHub Desktop.
Save cedmond/8851979 to your computer and use it in GitHub Desktop.
Check for breakpoints on window resize
$j(window).on('load resize',function(){
sizeCheck();
});
var currentBreak = -1;
var breakpoints = [788,522,320,0];
function sizeCheck() {
var screenBreak;
var screenW = $j(window).width();
for (var i = 0; i < breakpoints.length; i++) {
if( screenW > breakpoints[i]){
screenBreak = i;
break;
}
}
if (screenBreak != currentBreak) {
currentBreak = screenBreak;
var bp = breakpoints[i]; //this will be the px value defined in the breakpoints array
switch( currentBreak ){
case 0 : /* the first breakpoint or larger*/ ; break;
case 1 : /* second */ ; break;
case 2 : /* third */; break;
default : /* stuff that happens below the lowest one */;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment