Created
November 24, 2019 20:24
-
-
Save abilogos/66aba96bb0fb27ab3ed4a13245817d1e to your computer and use it in GitHub Desktop.
Getting browser Zoom level
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//for zoom detection | |
px_ratio = window.devicePixelRatio || window.screen.availWidth / document.documentElement.clientWidth; | |
$(window).resize(function(){isZooming();}); | |
function isZooming(){ | |
var newPx_ratio = window.devicePixelRatio || window.screen.availWidth / document.documentElement.clientWidth; | |
if(newPx_ratio != px_ratio){ | |
px_ratio = newPx_ratio; | |
console.log("zooming"); | |
return true; | |
}else{ | |
console.log("just resizing"); | |
return false; | |
} | |
} |
@RemcoSmitsDev : sorry to hear that, the script I have wrote is just detecting zooming and not the percentage.
one thing i want to mention that it is based on the css px which is different from pixels.
I have got a 4k monitor and I had set everything to scale 200% in order to show everything bigger.
maybe this could be the reason why you get 200%.
lets check your screen resolution here and see if it reports 1080p 0r 4k ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not working with an 4k iMac. When you have normal zoom level(
100%
) it will show up as200%
. Any ideas to wrap around this problem?