美文网首页
JS 获取浏览器显示比例,缩放比例

JS 获取浏览器显示比例,缩放比例

作者: 小棋子js | 来源:发表于2020-05-26 23:26 被阅读0次
ChangeRatio(){
        var ratio=0;
        var screen=window.screen;
        var ua=navigator.userAgent.toLowerCase();
        if(window.devicePixelRatio !== undefined){
            ratio=window.devicePixelRatio;    
        }else if(~ua.indexOf('msie')){
            if(screen.deviceXDPI && screen.logicalXDPI)
            {
                ratio=screen.deviceXDPI/screen.logicalXDPI;        
            }
        
        }else if(window.outerWidth !== undefined && window.innerWidth !== undefined){
            ratio=window.outerWidth/window.innerWidth;
        }
        console.log(ratio)
        if(ratio){
            ratio=Math.round(ratio*100);    
        }
        console.log(ratio)
        return ratio;
    },

相关文章

网友评论

      本文标题:JS 获取浏览器显示比例,缩放比例

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