Skip to content

Instantly share code, notes, and snippets.

@Kubo2
Last active January 26, 2021 12:44
Show Gist options
  • Save Kubo2/6c818624b2995cd34f20 to your computer and use it in GitHub Desktop.
Save Kubo2/6c818624b2995cd34f20 to your computer and use it in GitHub Desktop.
Detect zoom event in JavaScript
// 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);
}
})();
@rodrigorrch
Copy link

save my life. thanks

@indatawetrust
Copy link

indatawetrust commented Sep 2, 2018

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