Answer the question
In order to leave comments, you need to log in
Canvas, how to save a link to an element or access it?
In general, the essence is this:
I need to draw several squares on the canvas, and then have access to them and their data.
Answer the question
In order to leave comments, you need to log in
canvas, this is just a display, you cannot store any non-visual data on the canvas. So you just make normal JS objects, implement the draw method on them, and in the draw method, iterate over each such object (for example from an array), and call their draw method for your canvas. So you have a certain entity, an object that is drawn on the canvas, that has certain data (coordinates, dimensions, color), and they can be changed, and the changes will be redrawn on the next call to draw
UPD: I usually do this https: //jsfiddle.net/3bhr2ygz/8/ now you have an array of objects objects, and each object, when changed, reflects the changes on the canvas.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question