Forked from GianlucaGuarini/iPad-IOS7-landscape-fullscreen-hack.js
Last active
August 29, 2015 14:10
-
-
Save hughker/5f8ca5a65e93d29dacbe to your computer and use it in GitHub Desktop.
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
/*! | |
* | |
* Author: Gianluca Guarini | |
* Contact: gianluca.guarini@gmail.com | |
* Website: http://www.gianlucaguarini.com/ | |
* Twitter: @gianlucaguarini | |
* | |
* | |
**/ | |
if (navigator.userAgent.match(/iPad;.*CPU.*OS 7_\d/i)) { | |
var htmlTag = document.getElementsByTagName("html")[0], | |
onOrientationChange = function() { | |
if (window.orientation === 90 || window.orientation === -90) { | |
htmlTag.style.height = window.innerHeight + 'px'; | |
window.scrollTo(0, 0); | |
} else { | |
htmlTag.style.height = '100%'; | |
} | |
}; | |
window.addEventListener('orientationchange', onOrientationChange, false); | |
// to get the focus out of the keyboard | |
window.addEventListener('focusout', function(e) { | |
// it must be async because we must wait the end of the keyboard animation | |
setTimeout(onOrientationChange, 500, e); | |
}); | |
// to block the normal scroll behavior | |
htmlTag.addEventListener('touchmove', function(e) { | |
e.preventDefault(); | |
}, false); | |
onOrientationChange(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment