js获取浏览器当前缩放比例
废话不多说直接上代码function detectZoom() {var ratio = 0,//浏览器当前缩放比screen = window.screen,//获取屏幕ua = navigator.userAgent.toLowerCase();//判断登陆端是pc还是手机if (window.devicePixelRatio !== undefined) {
·
废话不多说直接上代码
function detectZoom() {
var ratio = 0,//浏览器当前缩放比
screen = window.screen,//获取屏幕
ua = navigator.userAgent.toLowerCase();//判断登陆端是pc还是手机
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);
}
if (ratio!=100) {
layer.msg("您当前的窗口缩放比例为" + ratio + "%建议您的窗口比例调为100%,窗口比例不为100%可能导致页面排版错乱");//这里layer是layui框架自带弹窗,如果不是layui可以使用alert()代替;
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)