Created
June 26, 2013 20:01
-
-
Save yitsushi/5871083 to your computer and use it in GitHub Desktop.
JavaScript: isBreakPoint #snippet
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
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; | |
} | |
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