What are the events on the canvas object that I can handle?

What are the events on the canvas object that I can handle. In particular, I am looking for a mouse event (either down, or up, etc.) that will give me x and y in the canvas.

+3
source share
2 answers

Here is a little [ Demo ] .

var canvas = document.getElementById("canvas");
canvas.onclick = function(e) {
  // mouse coordinates relative 
  // to the canvas element
  var position = canvas.getBoundingClientRect();
  var click = {
    x: e.clientX - position.left,
    y: e.clientY - position.top
  };
};
+4
source

DOM , () DOM. canvas - DOM, , , - . xy, , click canvas, x, y x, y canvas.

+3

Source: https://habr.com/ru/post/1776026/


All Articles