Screen orientation handler.
This module made of WebModule.
ScreenOrientation.on | ScreenOrientation.lock | |
---|---|---|
Chrome | ⭕ | ⭕ |
Chrome for Android | ⭕ | ⭕ |
Firefox for Android | ⭕ | ⭕ |
Edge | ⭕ | ⭕ |
Mobile Safari | ⭕ | ❌ |
IE10 | ❌ | ❌ |
IE11 (Windows 8.1) | ❌ | ❌ |
IE11 (Windows 7) | ❌ | ❌ |
Safari | ❌ | ❌ |
Android Browser | ❌ | ❌ |
<script src="<module-dir>/lib/WebModule.js"></script>
<script src="<module-dir>/lib/ScreenOrientationEvent.js"></script>
<script>
window.onload = function() {
if (ScreenOrientationEvent.enable) {
_setBodyColor(ScreenOrientationEvent.orientation());
ScreenOrientationEvent.on(function(currentOrientation, eventType) {
console.log(currentOrientation, eventType);
_setBodyColor(currentOrientation);
});
}
};
function _setBodyColor(orientation) {
var color = "white";
switch (orientation) {
case 0: color = "white"; break;
case 90: color = "red"; break;
case 180: color = "green"; break;
case 270: color = "blue"; break;
}
document.body.style.backgroundColor = color;
}
</script>