Skip to content

Instantly share code, notes, and snippets.

@mohsenheydari
Created January 8, 2019 01:36
Show Gist options
  • Save mohsenheydari/05193dd419cd2f9a352def31fdaed64e to your computer and use it in GitHub Desktop.
Save mohsenheydari/05193dd419cd2f9a352def31fdaed64e to your computer and use it in GitHub Desktop.
Transforms document cursor position to position relative to canvas
getRelativeCursorPosition(event){
var rect = this.canvas.getBoundingClientRect();
return {
x: event.clientX - rect.left,
y: event.clientY - rect.top
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment