Skip to content

Instantly share code, notes, and snippets.

@valpackett
Created January 5, 2013 17:40
Show Gist options
  • Save valpackett/4462678 to your computer and use it in GitHub Desktop.
Save valpackett/4462678 to your computer and use it in GitHub Desktop.
Landscape viewport fix (i.e. makes it 1024px on landscape iPad, 480px on landscape iPhone)
if (typeof window.orientation !== 'undefined') {
var viewport = document.querySelector('meta[name=viewport]');
function isLandscape() {
return window.orientation === 90 || window.orientation === -90;
}
function fixViewport() {
if (isLandscape()) { viewport.content = 'width=device-height' }
else { viewport.content = 'width=device-width' }
}
fixViewport();
window.addEventListener('orientationchange', fixViewport);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment