标签:for navigator navig 缩放 resize msi console xdp ges
$(document).ready(() => {
//阻止页面缩放
stopPageScale()
})
// 获得页面缩放比例
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;
};
//阻止页面缩放
var beforeRatio = detectZoom();
function stopPageScale(){
//一般电脑的缩放比例都在100~150之间(根据需要可改变默认缩放比例)
if(beforeRatio <= 100){
beforeRatio = 100//此处设置最小缩放为100
}else if(beforeRatio >= 150){
beforeRatio = 150//此处设置最大缩放为150
}
console.log(beforeRatio)
var scal = beforeRatio/detectZoom();
$(‘body‘).css(‘zoom‘,scal)
}
//动态计算页面缩放程度
window.onresize = function(){
stopPageScale()
}
标签:for navigator navig 缩放 resize msi console xdp ges
原文地址:https://www.cnblogs.com/baiyis/p/12791185.html