Skip to content

uupaa/ScreenOrientationEvent.js

Repository files navigation

ScreenOrientationEvent.js Build Status

npm

Screen orientation handler.

This module made of WebModule.

Documentation

Browser compatibility

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

Browser, NW.js and Electron

<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>

About

Screen orientation wrapper.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published