Skip to content

Instantly share code, notes, and snippets.

@tonylegrone
Created November 4, 2014 18:05
Show Gist options
  • Save tonylegrone/6d2bc57af4231fdb9e4c to your computer and use it in GitHub Desktop.
Save tonylegrone/6d2bc57af4231fdb9e4c to your computer and use it in GitHub Desktop.
Quick little function for testing screensize against breakpoints. Requires jQuery.
/**
* Determines if screen size is within givin breakpoint.
*
* @param (string) op
* The breakpoint size to compare. Supported sizes are medium, large, xlarge
* and giant.
*
* @param (bool) mobileFirst
* Changes comparison from <= to >= if set to false. Deafults to true.
*
* @return (bool)
*/
function breakPoint(op, mobileFirst) {
if (typeof(mobileFirst) === 'undefined') mobileFirst = true;
var breakPoints = {
medium: 480,
large: 640,
xlarge: 960,
giant: 1280,
};
if (mobileFirst) {
return parseInt($(window).width()) >= breakPoints[op];
}
else {
return parseInt($(window).width()) <= breakPoints[op];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment