Javascript examples for Canvas:Mouse
firefox mouse event on canvas
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> <style id="compiled-css" type="text/css"> .redborder {//from w w w . j av a2 s.c om border:solid 1px red; } </style> <script type="text/javascript"> $(window).load(function(){ $('#sketchCanvas').on("mousedown", function () { $('#sketchCanvas').on("mousemove", drawSketch); }); $('#sketchCanvas').on("mouseup mouseleave", function () { $('#sketchCanvas').off("mousemove", drawSketch); }); drawSketch = function (event) { var eTgt = $(event.target), eTgtPos = eTgt.offset(), x = (event.offsetX || event.clientX - eTgtPos.left), y = (event.offsetY || event.clientY - eTgtPos.top); $("#mouseXY").text("x: "+x + " y: " + y); }; }); </script> </head> <body> <canvas id="sketchCanvas" width="200" height="200" class="redborder"></canvas> <br> <span id="mouseXY" class="redborder">mouse coordinates</span> </body> </html>