-
-
Save kevingessner/5598913 to your computer and use it in GitHub Desktop.
<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> |
@aliok, there are multiple ways to hide an iframe: putting it into 1x1 parent with overflow: hidden
, for example.
BUT I don't understand why do we need an iframe, when normal window works as well—just need to add something like distinctUntilChanged
from RxJS. Just store current zoom level instead of creating an iframe.
@kirilldoid because when we zomm in or zoom out, the window doesn't resize, but all other elements do. When we zoom in, all elements in window get bigger, but the window is still in the same place with the same size.
i spend all of this time working on zoom bullshit, and NOW i find this.
WHY
Hi, neat solution. This method detects when you use the keyboard "command + shift + plus" or with the menu bar. However, if I pinch zoom, for some reason the zoom event doesn't trigger.. any tips on how to catch this case as well?
@amit777 For pinch zoom you need the Visual Viewport API.
Thanks a lot for this method.
While this works perfectly, to use in production we have to hide that frame.
I used this one:
Firefox (and perhaps Safari too) doesn't trigger the event if
display:none;
, so cannot use that.