Monday, 15 April 2013

html - Onclick on image that is created in a javascript canvas -



html - Onclick on image that is created in a javascript canvas -

hiho, prepared snippet.

as in illustration i'm using drawimage function draw images game, because don't want include them in html ... however, problem is, can't find possibility give "own created" images onclick function. thought object "image" (var someimage = new image();) comparable html <img> or <input type="image">, no matter how hard try, can't create it.

can help me?

you've given click event canvas context , not canvas, alter to:

mycanvas.onclick = function()

as making individual images clickable (if draw more one), can maintain array of clickable areas , links should go correspond images, add together loop canvas click check mouse co-ords match on of areas in array.

example : jsfiddle code

javascript html canvas onclick drawing

No comments:

Post a Comment