Skip to content

Instantly share code, notes, and snippets.

@dzava
Created July 3, 2015 00:36
Show Gist options
  • Save dzava/39423bc9cc0439c83834 to your computer and use it in GitHub Desktop.
Save dzava/39423bc9cc0439c83834 to your computer and use it in GitHub Desktop.
function getSquare(canvas, evt) {
var rect = canvas.getBoundingClientRect();
var values = this.scroller.getValues();
return {
x: Math.ceil((((evt.clientY - rect.top + values.top) / values.zoom) - ((evt.clientY - rect.top + values.top)/values.zoom) % cellHeight) / cellHeight),
y: Math.ceil((((evt.clientX - rect.left + values.left) / values.zoom) - ((evt.clientX - rect.left + values.left)/values.zoom) % cellWidth) / cellWidth)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment