Skip to content

Instantly share code, notes, and snippets.

@maxlee
Created October 20, 2013 06:07
Show Gist options
  • Select an option

  • Save maxlee/7065530 to your computer and use it in GitHub Desktop.

Select an option

Save maxlee/7065530 to your computer and use it in GitHub Desktop.
var detectZoom = function(){
var ratio = 0,
screen = window.screen,
ua = navigator.userAgent.toLowerCase();
if( ~ua.indexOf('firefox') ){
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 );
}
// 360安全浏览器下浏览器最大化时诡异的outerWidth和innerWidth不相等
if( ratio === 99 || ratio === 101 ){
ratio = 100;
}
return ratio;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment