美文网首页
移动端横竖屏最佳解决方案

移动端横竖屏最佳解决方案

作者: 周三胖 | 来源:发表于2017-02-17 17:22 被阅读0次
    function recordOrient() {
        var storage = localStorage;
        var data = storage.getItem('J-recordOrientX');
        var w = document.documentElement.clientWidth,
            h = document.documentElement.clientHeight;
        var _Width = 0,
            _Height = 0;
        if(!data) {
            _Width = window.screen.width;
            _Height = window.screen.height;
            storage.setItem('J-recordOrientX',_Width + ',' + _Height);
        }else {
            var str = data.split(',');
            _Width = str[0];
            _Height = str[1];
        }
        if(w == _Width) {
            // 竖屏
            return;
        }
        if(w == _Height){
            // 横屏
            return;
        }
    }
    detectOrient();
    window.addEventListener('resize',detectOrient);
    

    相关文章

      网友评论

          本文标题:移动端横竖屏最佳解决方案

          本文链接:https://www.haomeiwen.com/subject/ocslwttx.html