Skip to content

Instantly share code, notes, and snippets.

@kevingessner
Created May 17, 2013 13:09
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kevingessner/5598913 to your computer and use it in GitHub Desktop.
Save kevingessner/5598913 to your computer and use it in GitHub Desktop.
Detect browser zoom in javascript 'zoom' event is triggered on window on every browser zoom change. No polling!
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
<iframe id="frame" style="width: 250px; border: solid 1px red;" ></iframe>
<script type="text/javascript">
var elFrame = $('#frame')[0];
$(elFrame.contentWindow).resize(function() {
$(window).trigger('zoom');
});
$(window).on('zoom', function() {
console.log('zoom', window.devicePixelRatio);
});
</script>
</body>
</html>
@R2D221
Copy link

R2D221 commented Jul 17, 2020

@amit777 For pinch zoom you need the Visual Viewport API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment