如何更改Fabric.js对象的值? [英] How do I change a value for a Fabric.js object?

查看:918
本文介绍了如何更改Fabric.js对象的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Fabric.js 画布。我还有一个javascript,它有一个按下按钮时被调用的函数。我知道如何获取活动对象, canvas.getActiveObject(),但我不知道如何更改其中的值而无需进行克隆和删除原本的。我之所以想改变原版是因为当再次按下按钮时,会发生奇怪的事情。有关如何执行此操作的任何线索?

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.getActiveObject(), but i don't know how to just change a value in it without having to make a clone and deleting the original. The reason why i just want to change the original is because when the button is pressed again, weird things happen. Any clue on how to do this?

推荐答案

有许多值的getter和setter:

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});

如果更改影响属性的维度或位置,则必须调用 object.setCoords ()更改属性后。否则,对象的点击区域是错误的。
更改属性后,您必须调用 canvas.renderAll()重新渲染所有对象。

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.

有关详细信息,请查看文档: fabricjs.com/docs/fabric.Object.html

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

这篇关于如何更改Fabric.js对象的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆