Finding mouse position on canvas. Is there a better way?
I have a canvas 2000 px wide, which fits the width of the client window.
If I use a mouse event with event.clientX I must calculate the relative position with respect to the window width.
If I use a mouse event with event.clientY I must calculate the relative position with respect to the window width plus offset due to the scrolling of the window.
$(canvas).mousedown(grdown.bind(this));
function grdown(e){
var rect = canvas.getBoundingClientRect();
console.log("clientX " + (e.clientX * (2000/canvas.width)) + " clientY " + ((e.clientY * (2000/canvas.width))-rect.top * (2000/canvas.width) ) );
} // this eventListener is done with jQuery
Is there a simpler way to do this?
