Last active
August 29, 2015 14:05
Checking Standard Window Sizes
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
$( 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