Let's say that I have the following JS code:
function getPositions() {
document.getElementById("gm").addEventListener("click", () => {
let data = [event.clientX, event.clientY];
return data;
});
}
function completeChecking() {
let coors = getPositions();
return coors;
}
And a canvas tag in HTML:
<canvas onmouseover="completeChecking();" id="gm" width="512" height="512"></canvas>
I want to know the coordinates of the user's mouse whenever it hovers over the canvas
element.
I know that I can set an initiated
, or fired
variable inside the function, and set it to true whenever the function is called. But I want it to be false whenever the user's mouse is not in the canvas
and true when it is.
Is there a way to do this?