Last active
August 29, 2015 14:06
-
-
Save anova/169824fa1f0f458b4ab3 to your computer and use it in GitHub Desktop.
Learn mobile device width by its orientation.
This file contains 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
window.info = function() { | |
var i = ''; | |
i += 'screen.width =' + screen.width + '\n'; | |
i += 'screen.height =' + screen.height + '\n'; | |
i += 'window.orientation =' + window.orientation + '\n'; | |
i += 'window.getWidth() =' + window.getWidth() + '\n'; | |
alert(i); | |
};//window.info | |
window.getWidth = function() { | |
if(typeof window.orientation == "undefined") return document.body.clientWidth; | |
var angle = Math.abs(window.orientation % 180); | |
switch(angle) { | |
case 0: | |
return screen.width; | |
break; | |
case 90: | |
return screen.height; | |
break; | |
} | |
};//window.getWidth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment