0

How do I get the coordinates of the mouse?

How do I get the coordinates of the mouse in JS ( or other languages that are used to make webpages ) on a canvas / SVG (whichever)? As example, if I want to make a button on a canvas that should be clicked and its in the middle of the canvas and ten times smaller than the canvas, is it possible to make something like the "onclick" event handler without making a HTML button, by making a button image on the canvas?

4th Aug 2018, 2:02 PM
Joel Kronqvist
Joel Kronqvist - avatar
2 Respostas
+ 4
You just have to check if the mouse click is within the area of the canvas button. Here's a reference for the mouse event https://www.w3schools.com/jsref/event_clientx.asp
4th Aug 2018, 2:08 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
0
Thanks, that was really helpful.
4th Aug 2018, 5:05 PM
Joel Kronqvist
Joel Kronqvist - avatar