您的位置:首页 > 其它

判断浏览器缩放比例

2018-01-25 14:17 183 查看
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;

};

detectZoom();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: