Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save belden/748f04eed6889c3204ff309dc69c806d to your computer and use it in GitHub Desktop.
Save belden/748f04eed6889c3204ff309dc69c806d 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