前几天在做项目的时候遇到浏览器缩放比例不为100%时,出来的页面不正常,于是找到了方法获取其比例来通知用户
function detectZoom (){ ??var ratio = 0, ???screen = window.screen, ???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; ?} ????if (ratio){ ???ratio = Math.round(ratio * 100); ?} ????return ratio;};
推荐地址:http://www.jb51.net/article/55753.htm
js获取浏览器缩放比例
原文地址:https://www.cnblogs.com/xiaoyaoxingchen/p/9057387.html