Skip to content

Instantly share code, notes, and snippets.

@pixelhijack
Last active September 30, 2016 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pixelhijack/9630293 to your computer and use it in GitHub Desktop.
Save pixelhijack/9630293 to your computer and use it in GitHub Desktop.
get exact cross browser mouse event coordinates workarounds
/*
get exact cross browser mouse event coordinates workarounds (relative to offset parent)
*/
/* with jquery */
var x = event.offsetX || event.clientX - $(event.target).offset().left,
y = event.offsetY || event.clientY - $(event.target).offset().top;
/* on svg raphael paper */
var x = e.offsetX == undefined ? e.layerX : e.offsetX,
y = e.offsetY == undefined ? e.layerY : e.offsetY;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment