Skip to content

Instantly share code, notes, and snippets.

@Kubo2

Kubo2/onzoom.js

Last active Jan 26, 2021
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@rodrigorrch rodrigorrch commented Aug 8, 2017

save my life. thanks

@indatawetrust

This comment has been minimized.

Copy link

@indatawetrust 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