Last active
August 29, 2015 14:05
-
-
Save jeremyzahner/b24e8b30451ad2b45c2a to your computer and use it in GitHub Desktop.
Detect Mobile Orientation (Overlay for Portrait)
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
var updateorientation = function (){ | |
var classname = '', | |
mql = window.matchMedia("(orientation: portrait)"), | |
top = 100; | |
function handleOrientationChange(mql) { | |
if (mql.matches) { | |
if ($('#overlay').length === 0) { | |
window.scrollTo(0, 1); | |
$('body').append('<div id="overlay" style="width: 100%; height:' + $(document).height() + 'px; max-height: 100%; max-width: 100%; position: absolute; background-color: white; top: 0; left: 0; z-index: 999999999999; background-image: url(/assets/images/orientation.svg); background-repeat: no-repeat; background-position: center center; background-size: 20%;"><span style="top: ' + top + 'px; margin-top: 30%; float: none; text-align: center; display: block;">Bitte halten Sie Ihr Tablet quer.</span></div>'); | |
} | |
} else { | |
$('#overlay').remove(); | |
} | |
} | |
var mql = window.matchMedia("(orientation: portrait)"); | |
mql.addListener(handleOrientationChange); | |
handleOrientationChange(mql); | |
if (mql.matches) { | |
if ($('#overlay').length === 0) { | |
window.scrollTo(0, 1); | |
$('body').append('<div id="overlay" style="width: 100%; height:' + $(document).height() + 'px; max-height: 100%; max-width: 100%; position: absolute; background-color: white; top: 0; left: 0; z-index: 999999999999; background-image: url(/assets/images/orientation.svg); background-repeat: no-repeat; background-position: center center; background-size: 20%;"><span style="top: ' + top + 'px; margin-top: 30%; float: none; text-align: center; display: block;">Bitte halten Sie Ihr Tablet quer.</span></div>'); | |
} | |
} else { | |
$('#overlay').remove(); | |
} | |
}; | |
updateorientation(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment