Capturing click event on a canvas - Javascript Canvas

Javascript examples for Canvas:Mouse

Description

Capturing click event on a canvas

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){//from  w  ww.  j ava2 s  .c o  m
var can = document.getElementById('canvas1');
var ctx = can.getContext('2d');
can.addEventListener('mousedown', function() {console.log('down!')}, false);
    });

      </script> 
   </head> 
   <body> 
      <input style="position: absolute;" value="some input"> 
      <canvas id="canvas1" width="500" height="500" style="border: 1px solid black;"></canvas>  
   </body>
</html>

Related Tutorials