First, here's browser status refers to the page the user clicks on the top left corner of the browser zoom plus / minus generated overall change into small cases (shortcut: Ctrl + Plus or Ctrl + Minus or Ctrl + scroll wheel up and down)
Codes are as follows:
If detectZoom function return value is the default zoom level is 100, more than 100 is enlarged, less than 100 is reduced.
1 function detectZoom (){ 2 var ratio = 0, 3 screen = window.screen, 4 ua = navigator.userAgent.toLowerCase(); 5 6 if (window.devicePixelRatio !== undefined) { 7 ratio = window.devicePixelRatio; 8 } 9 else if (~ua.indexOf('msie')) { 10 if (screen.deviceXDPI && screen.logicalXDPI) { 11 ratio = screen.deviceXDPI / screen.logicalXDPI; 12 } 13 } 14 else if (window.outerWidth !== undefined && window.innerWidth !== undefined) { 15 ratio = window.outerWidth / window.innerWidth; 16 } 17 18 if (ratio){ 19 ratio = Math.round(ratio * 100); 20 } 21 22 return ratio; 23 };
var ratio = detectZoom () // Print scale value the console.log (ratio) // determines whether scaling IF (ratio> 100 ) { the console.log ( "amplification la" ) } the else IF (ratio <100 ) { Console. log ( "narrowing" ) } the else { the console.log ( "100%" ) }