How do I change a value for a Fabric.js object?

后端 未结 2 1985
刺人心
刺人心 2021-01-21 04:28

I have a Fabric.js canvas. I also have a javascript that has a function that gets called when a button is pressed. I know how to get the active object, canvas

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-21 04:57

    There are many getters and setters for values:

    object.setWidth(val);
    object.setHeight(val);
    object.setStrokeWidth(val);
    object.setLeft(val);
    object.setTop(val);
    

    You can also change values with general set method:

    object.set('width', value);
    object.set({ width: value, height: value});
    

    If you change dimension or position affecting properties you have to call object.setCoords() after changing the property. Otherwise the "click area" of the object is wrong. After changing properties you have to call canvas.renderAll() to re-render all objects.

    For more information just have a look at the docs: fabricjs.com/docs/fabric.Object.html

提交回复
热议问题