Skip to content

Instantly share code, notes, and snippets.

@caot
Forked from abilogos/detect-zoom.js
Created March 10, 2023 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caot/44e64f4fb102767839b2aef85dd739fc to your computer and use it in GitHub Desktop.
Save caot/44e64f4fb102767839b2aef85dd739fc to your computer and use it in GitHub Desktop.
Getting browser Zoom level
//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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment