I don't think you can listen for events from images that are drawn on the canvas. So what I think is that you can listen for click events on the document or just on the canvas and then check if the click occured on the area of the canvas occupied by the button.
$('canvas').on('click', function(e) {
if (e.pageX >= leftEdgeOfButton && e.pageX <= rightEdgeOfButton
&& e.pageY >= topEdgeOfButton && e.pageY <= bottomEdgeOfButton) {
// handle click event
}
});
As for the position of the edges of the button, I'm pretty sure you can calculate those values: the left and top edges are probably just the same as the coordinate values you used to define where the image should be drawn, and the right/bottom are just the left or right edges plus the width or height of the button.
If the canvas is not of the same size with the whole screen, you can add the left and top offset of the canvas to the e.pageX and e.pageY to make and adjustment.
$('canvas').on('click', function(e) {
if (e.pageX + leftOffsetOfCanvas >= leftEdgeOfButton
&& e.pageX + leftOffsetOfCanvas <= rightEdgeOfButton
&& e.pageY + leftOffsetOfCanvas >= topEdgeOfButton
&& e.pageY + leftOffsetOfCanvas <= bottomEdgeOfButton) {
// handle click event
}
});
You can use jQuery's .offset() function to get the top and left offsets of the canvas element.