首页 > Web开发 > 详细

js判断页面放大缩小

时间:2015-09-21 11:55:46      阅读:227      评论:0      收藏:0      [点我收藏+]

项目中,经常会碰到页面被放大或者缩小,导致页面显示错误,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 事件可用于检测页面是否触发了放大或缩小。

js判断页面放大缩小

原文:http://www.cnblogs.com/ayseeing/p/4825517.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!