简体   繁体   中英

How do you get the id from the fabricjs canvas object?

How do I get the id element from a fabricjs canvas object? I understand I pass in an ID into the constructor when I make a new one, but after it has been constructed. How do I get the id from the canvas object I just created?

It seems like such a simple thing, but yet I can't find it.

var newCanvas = new fabric.Canvas("myId");
var newCanvasId = newCanvas.id;    //doesn't work, undefined

new fabric.Canvas() does not return a Canvas DOM Element but rather a FabricJS Canvas object with its own set of attributes and methods. If you want to access the actual canvas that FabricJS paints on, there's a getElement() method:

var newCanvas = new fabric.Canvas("myId");
var newCanvasId = newCanvas.getElement().id; // "myId"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM