Ho un problema con la funzione click in javascript. Questo è il mio codice:javascript canvas detect click on shape
var canvas = document.getElementsByTagName("canvas")[0];
var ctx = canvas.getContext('2d');
BigCircle = function(x, y, color, circleSize) {
ctx.shadowBlur = 10;
ctx.shadowColor = color;
ctx.beginPath();
ctx.arc(x, y, circleSize, 0, Math.PI * 2, true);
ctx.fill();
ctx.closePath();
};
var bigGreen = new BigCircle(1580, 800, '#5eb62b', 180);
function init() {
$("#bigGreen").click(function(e){
alert("test");
});
}
$(document).ready(function() {
init();
});
Ma l'evento click non funziona! Qualcuno sa perché? Grazie mille in anticipo!
È necessario inserire il codice HTML - non riesco a vedere che cosa " canvas "o" bigGreen "sono, e questo è probabilmente il problema, in una mancata corrispondenza di H Nomi TML e JavaScript. –
oh scusa, ecco l'HTML: http://jsfiddle.net/Babsi/eadBu/1/ – user1590534
Questo post può aiutare: https: // medio.com/devtravel/hit-region-detection-for-html5-canvas-e-how-to-listen-click-events-on-canvas-shapes-815034d7e9f8 # .wgzhx52ns – lavrton