Click here to Skip to main content
15,884,040 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created an image and a load of functions, however I am not sure how to write a function that calls those functions when I click on certain areas of the canvas. For example if I wanted to make a small square of an image run a function rather than having the entire image run it.

If anyone could write some code to allow me to do this I would be very grateful. I have not managed to find anything helpful on google.
Posted

1 solution

Try this. You can hack it with an image map overlayed. Make sure you set the z order of the canvas to put the blank image and its map on top.

XML
<!DOCTYPE html>
<html>
<body>

<p>Click on the canvas.</p>

<img width="398" height="398" alt="Canvas" usemap="#canvasmap" style="border:1px red solid"/>


<map name="canvasmap">
  <area shape="rect"   coords="0,0,50,50"      onclick="alert('You clicked area 1')" >
  <area shape="rect"   coords="100,100,50,50"  onclick="alert('You clicked area 2')" >
  <area shape="rect"   coords="300,300,50,50"  onclick="alert('You clicked area 3')" >
</map>

<CANVAS id='c1' width='402' height='402' style='border: 1px black solid;position:absolute;top:50px;left:6px;z-index:-1'>

</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900