js根据当前网页的缩放比例修改样式

2024年08月02日 建站教程

获取当前页面的缩放值,来修改样式!

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;
};

//开始判断

if(detectZoom()==200){ }else{ }

本文链接:http://so.lmcjl.com/news/9766/

展开阅读全文
相关内容