Skip to content

Instantly share code, notes, and snippets.

@ripter
Last active October 2, 2021 18:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ripter/0aafa71bc2d501dc69b5 to your computer and use it in GitHub Desktop.
Save ripter/0aafa71bc2d501dc69b5 to your computer and use it in GitHub Desktop.
Adds MouseEvent .offsetX and .offsetY to Firefox
// polyfill for event.offsetX/offsetY
// Firefox is the only browser that doesn't support it (IE has since 4)
(function() {
var evt = document.createEvent('MouseEvent');
if (evt.offsetX === void 0) {
Object.defineProperties(MouseEvent.prototype, {
'offsetX': {
get: function() {
return this.layerX - this.target.offsetLeft;
}
}
, 'offsetY': {
get: function() {
return this.layerY - this.target.offsetTop;
}
}
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment