Created
October 15, 2019 22:00
-
-
Save souporserious/b44ea5d04c38c2e7ff32cd1912a17cd0 to your computer and use it in GitHub Desktop.
Checks if window has been zoomed.
This file contains hidden or 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
// modified from https://stackoverflow.com/a/52008131/1461204 | |
const zoomEvent = new Event('zoom') | |
let currentRatio = window.devicePixelRatio | |
function checkZooming() { | |
if (currentRatio !== window.devicePixelRatio) { | |
window.dispatchEvent(zoomEvent) | |
} | |
} | |
window.addEventListener('resize', checkZooming) | |
// usage | |
window.addEventListener('zoom', () => { | |
console.log('zoomed!') | |
}) |
@megasent1 thanks! I should have mentioned that, my bad. Here's a link to a Resize Observer polyfill if anyone needs it. Can confirm it works in Safari.
Be aware that https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver is not compatible with Safari and IE
It is now
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Be aware that https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver is not compatible with Safari and IE