P
P
Proger59132020-12-05 23:32:31
JavaScript
Proger5913, 2020-12-05 23:32:31

How to click on canvas using javascript?

The title says it all. The goal is to click on the hero (more precisely, not a cell, no difference) on the field, googling and trying out 1 single working method, it turned out that it does not work. Here is the code and the game itself:

$('canvas:eq(1)').on("mousedown mouseup", function(e) {    
console.log(e.type + " event fired at coords: " + e.pageX + ", " + e.pageY);
});

x_coord = 220;
y_coord = 220;

var e = jQuery.Event( "mousedown", { pageX: x_coord, pageY: y_coord } );
$('canvas:eq(1)').trigger(e);

// execute more code
x_coord = 220;
y_coord = 220;

var e = jQuery.Event( "mouseup", { pageX: x_coord, pageY: y_coord } );
$('canvas:eq(1)').trigger(e);.

Unfortunately, the image could not be uploaded here
https prnt.sc vwj46p

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question