How can I use JavaScript to track the mouse position on a canvas?
Upon visiting this page: http://billmill.org/static/canvastutorial/mouse.html
They provide this code snippet:
function initializeMouse() {
canvasMinimumX = $("#canvas").offset().left;
canvasMaximumX = canvasMinX + WIDTH;
}
function handleMouseMove(event) {
if (event.pageX > canvasMinimumX && event.pageX < canvasMaximumX) { // How do you access canvasMinimumX outside of its scope?
// Also, what is pageX? Is it the mouse coordinate? If not, how can I obtain it?
paddleLocationX = event.pageX - canvasMinimumX;
}
}
$(document).mousemove(handleMouseMove);
And lastly, I want this action to occur on mouse click. So, I write:
$(document).click(onMouseClick)
Is that correct?