Last active
October 2, 2021 18:18
-
-
Save ripter/0aafa71bc2d501dc69b5 to your computer and use it in GitHub Desktop.
Adds MouseEvent .offsetX and .offsetY to Firefox
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
// 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