HTML Canvas Mouse Event Handler

Description

HTML Canvas Mouse Event Handler

View in separate window

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Event Demo</title>
   /*from  w  w w. ja v  a  2  s.  c  o  m*/
  </head>
  <body>
    <canvas id="canvas" width="400" height="400"></canvas>
    <aside>Open debugging console in web browser and click mouse.</aside>
    
    <script>
    window.onload = function () {
      var canvas = document.getElementById('canvas');
        
      canvas.addEventListener('mousedown', function (event) {
        console.log("mouse down");
      }, false);
        
      canvas.addEventListener('mouseup', function (event) {
        console.log("mouse up");
      }, false);
    };
    </script>
  </body>
</html>



PreviousNext

Related