Skip to content

Instantly share code, notes, and snippets.

@RobinHerbots
Forked from ripter/event-offset-polyfill.js
Created October 2, 2021 18:18
Show Gist options
  • Save RobinHerbots/a2cfbe0cabb9893a8de6e543df712033 to your computer and use it in GitHub Desktop.
Save RobinHerbots/a2cfbe0cabb9893a8de6e543df712033 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