Cannot use getActiveObject() in Fabric.js
13,818
getActiveObject()
is a method of a fabric.Canvas object.
With the above code, you would use stage.getActiveObject()
instead of canvas.getActiveObject()
Author by
Robin Riegman
Updated on June 04, 2022Comments
-
Robin Riegman almost 2 years
I want to check the image quality of the selected image on canvas.
My following code:
var canvas = $(".canvas-container").children('canvas').get(0); //console.log(canvas.getActiveObject().get('type')); console.log(canvas);
The getActiveObject() log gives an error: undefined is not a function.
The other log returns:
<canvas class="lower-canvas" width="850" height="230" style="position: absolute; width: 850px; height: 230px; left: 0px; top: 0px; -webkit-user-select: none;"></canvas>
The canvas is created in another js file:
//create fabric stage var canvas = $productStage.children('canvas').get(0); stage = new fabric.Canvas(canvas, { selection: false, hoverCursor: 'pointer', rotationCursor: 'default', controlsAboveOverlay: true, centeredScaling: true });
What must I change so I can use so I can use canvas.getActiveObject()?
See http://www.panel-it.eu/shop/straatnaambord-3/# for reference.
Thanks in advance.
-
Robin Riegman over 9 yearsIf I use stage.getActiveObject() the console says undefined. console.log(stage.getActiveObject()); What am I doing wrong?
-
taveras over 9 yearsIf you have lost the reference to the fabric.Canvas object you created called
stage
, then perhaps you should attach it to the HTMLElement object of the canvas when you initialize the fabric Canvas. See stackoverflow.com/a/13195555/3538503 for an example.