Skip to content

Instantly share code, notes, and snippets.

@bvanasse
Last active August 29, 2015 14:05
Show Gist options
  • Save bvanasse/39e63d044aa70df62ecc to your computer and use it in GitHub Desktop.
Save bvanasse/39e63d044aa70df62ecc to your computer and use it in GitHub Desktop.
Checking Standard Window Sizes
$( document ).ready(function(){
var w = checkWindowSize();
$("body").removeClass("tiny small medium large xlarge huge");
if(w.size){ $("body").addClass(w.size) };
});
$( window ).resize(function() {
var w = checkWindowSize();
$("body").removeClass("tiny small medium large xlarge huge");
if(w.size){ $("body").addClass(w.size) };
});
function checkWindowSize(){
// Returns .width and .size
var width = $(window).width();
var height = $(window).height();
var o = Object();
o.width = width;
o.height = height;
if($(window).width() <= 420){
// Mobile Sizes
// iPhone6 Plus: 414
// iPhone6 : 375
// iPhone5, iPhone4 : 320
o.size = "tiny";
} else {
if($(window).width() <= 768){
// Tablet Sizes
// iPad: 768
o.size = "small";
} else {
if($(window).width() <= 1280){
o.size = "medium";
} else {
if($(window).width() <= 1600){
o.size = "large";
} else {
if($(window).width() <= 1920){
o.size = "xlarge";
} else {
o.size = "huge";
}
}
}
}
}
return o;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment