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

2020-05-26  本文已影响0人  小棋子js
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;
    },
上一篇 下一篇

猜你喜欢

热点阅读