javascript getOrientation_of_device_Landscape_Portrait

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript getOrientation_of_device_Landscape_Portrait相关的知识,希望对你有一定的参考价值。


        // V01 20181012

        // ohne Extension 
        // ohne AdServer-Template
        // funktioniert in allen mobilen Devices

        function getOrientationAll() {
            var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
            var orientationType = screen.msOrientation || (screen.orientation || screen.mozOrientation || {}).type; // e.g. "portrait-primary"
            var windowOrientation = '';

            if (isIOS){ // apple
                windowOrientation = window.orientation;

                if (Math.abs(windowOrientation) === 90) {
                    orientationType = 'Landscape';
                } else {
                    orientationType = 'Portrait';
                }
            } else { // everything else
                var firstLetter = orientationType.slice(0, 1).toLowerCase();
                if (firstLetter === 'l') {
                    orientationType = 'Landscape';
                } else {
                    orientationType = 'Portrait';
                }
            }
            // output
            document.getElementById('mainContainer').innerHTML = orientationType;
        }

        // Call/request the mode once on initial load and afterwards on orientationchange
        getOrientationAll();

        myFT.on("orientationchange", function(){
            getOrientationAll();
        });

        window.addEventListener('orientationchange', function(){
            getOrientationAll();
        });
        
        
        

以上是关于javascript getOrientation_of_device_Landscape_Portrait的主要内容,如果未能解决你的问题,请参考以下文章

如何从 getOrientation() 和 Open CV 代码返回方向角度?

Lua - getOrientation() throw Attempt to call global (a nil value)

磁场、旋转矩阵和全局坐标

android中过度滚动的视觉指示

OpenCV 3 中的 PCA 错误

固定方向Android上的设备旋转