M
M
MAXH02011-12-25 23:08:01
JavaScript
MAXH0, 2011-12-25 23:08:01

Click on canvas - how to get coordinates correctly?

The question is generally obvious, but I did not find a convenient code (I'm just a fan of programming in JavaScript)
Regarding the window and the document, the coordinates are obtained easily. How about canvas?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FrostMoon, 2011-12-25
@MAXH0

x = pageY - canvasElement.offsetLeft;
y = pageX - canvasElement.offsetTop;
where pageY and pageX are coordinates relative to the document.

S
Sererator, 2012-01-05
@Serator

msdn.microsoft.com/en-us/library/ms530302%28VS.85%29.aspx is a good article on MSDN about sizes and coordinates. Better than this on the net did not meet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question