Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fabric.js - get New Height after redimensioning

I create group with:

var text    = new fabric.Text(textValue,{left: 20, top: 30, fontSize:25});
var rect    = new fabric.Rect({
                    width       : text.get('width') + 40,
                    fill        : "#FFFFFF",
                    height      : 100,
                    stroke      : '#000000',
                    strokeWidth : 1

                  });

    var myGroupObj = new fabric.CustomGroup([  rect,text ], {
      left      : 0,
      top       : 0,
    });

Now whene I manually resizes my group and I want to get a new heigth.

myGroupObj.get('height')

I have always last one (100). Somme idea to get new height, please?

like image 803
medkhelifi Avatar asked Dec 25 '22 06:12

medkhelifi


1 Answers

Instead of accessing the .height attribute, you should call the getHeight() function, which gives you the actual height (the one you see on the screen) of a fabric.js object. In the code you have created on jsfiddle, to get the real height, you should change the line alert(activeObject.height); by alert(activeObject.getHeight()); and you will see the difference.

Cheers, Gonzalo Gabriel

like image 199
ggmendez Avatar answered Jan 04 '23 21:01

ggmendez