Skip to content

Instantly share code, notes, and snippets.

@anova
Last active August 29, 2015 14:06
Show Gist options
  • Save anova/169824fa1f0f458b4ab3 to your computer and use it in GitHub Desktop.
Save anova/169824fa1f0f458b4ab3 to your computer and use it in GitHub Desktop.
Learn mobile device width by its orientation.
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