ayseeing

项目中,经常会碰到页面被放大或者缩小,导致页面显示错误,js可以判断页面放大缩小。

// 若返回100则为默认无缩放,如果大于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;
};

  window.onresize 事件可用于检测页面是否触发了放大或缩小。

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-11
  • 2021-11-01
  • 2021-05-27
  • 2022-01-03
  • 2021-11-15
  • 2022-12-23
猜你喜欢
  • 2021-10-16
  • 2021-12-30
  • 2021-10-16
  • 2022-12-23
  • 2021-10-16
  • 2021-10-16
  • 2021-11-27
相关资源
相似解决方案