Add mouse events to the elements drawn in HTML5 Canva using Jtopo
When using HTML5, what is drawn on canvas is not appropriate for mouse events, but adding events using Jtopo is very simple, and the effect is as follows:
code example:
var node = new jtopo.node ("Hello"); Node.setLocation (
409, 269); Node.mousedown (function (event) {if (event.button == 2) {node.text = ' right key ';} Else if (event.button == 1) {node.text = ' Press the Middle key ';}
Else if (event.button == 0) {node.text = ' press the left key ';}}); Node.mouseup (function (event) {if (event.button == 2) {node.text = ' release right key ';} Else if (event.button == 1) {node.text = ' loosen the middle key ';}
Else if (event.button == 0) {node.text = ' release left Key ';}});
Node.click (function (event) {Console.log ("click");});
Node.dbclick (function (event) {Console.log ("double-click");});
Node.mousedrag (function (event) {Console.log ("drag");});
Node.mouseover (function (event) {Console.log ("mouseover");});
Node.mousemove (function (event) {Console.log ("MouseMove");}); Node.mouseout (function (event) {Console.log ("mouseout");});
Example Two
Q: with the HTML5 canvas picture, how to add mouse events (such as: Move in, click), thank you for your advice!
Answer one:
Object-oriented can be
One is you look for the canvas framework of the object, like Canvasjs.
One is you write your own object structure
Simply put, you canvas all the elements in the picture, like the circle, the line.
Each object has to implement mouse events Mouseon and so on each object to know its own coordinates and size (rectangle size)
But how do you trigger it? Bind all mouse events to canvas and then check the coordinates to see that the object is touched and then invoke the corresponding mouse event of the object
Answer two:
Instead of adding a mouse event to the graphic, you determine which shape is under the mouse in the mouse event. Such as
<! doctype>