Last active
January 26, 2021 12:44
-
-
Save Kubo2/6c818624b2995cd34f20 to your computer and use it in GitHub Desktop.
Detect zoom event in JavaScript
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
// set zoom event | |
window.onzoom = function(e) { | |
// zoom event | |
} | |
// detect resize | |
(function() { | |
var oldresize = window.onresize; | |
window.onresize = function(e) { | |
var event = window.event || e; | |
if(typeof(oldresize) === 'function' && !oldresize.call(window, event)) { | |
return false; | |
} | |
if(typeof(window.onzoom) === 'function') { | |
return window.onzoom.call(window, event); | |
} | |
})(); |
window.onzoom = function(e) {
// zoom event
};
// detect resize
(function() {
var oldresize = window.onresize;
window.onresize = function(e) {
var event = window.event || e;
if(typeof(oldresize) === 'function' && !oldresize.call(window, event)) {
return false;
}
if(typeof(window.onzoom) === 'function') {
return window.onzoom.call(window, event);
}
}
})();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
save my life. thanks