是否可以Fabric.js按名称获取对象?我可以添加子类,这将允许我向对象添加自定义名称属性.但之后我可以通过名称而不是索引来调用对象吗?例如
按索引调用 canvas.getItem(0);
我想要类似的东西 canvas.getItemByName(itemName);
有以下问题:
试图将fabric.Group子类化:
var CustomGroup = fabric.util.createClass(fabric.Group, {
type : 'customGroup',
initialize : function(objects, options) {
options || ( options = { });
this.callSuper('initialize', objects, options);
this.set('customAttribute', options.customAttribute || 'undefinedCustomAttribute');
},
toObject : function() {
return fabric.util.object.extend(this.callSuper('toObject'), {
customAttribute : this.get('customAttribute')
});
},
_render : function(ctx) {
this.callSuper('_render', ctx);
}
});
Run Code Online (Sandbox Code Playgroud)
测试用例:
我创建一个红色矩形并将其添加到自定义组:
function drawTestRect() {
// create a rectangle object
var rect = new fabric.Rect({
left : 100,
top : 100,
fill : 'red',
width : 20,
height : 20 …Run Code Online (Sandbox Code Playgroud) 我想fabric.Polygon在 Fabric.js 中绘制一个鼠标交互。我做了一个小 jsfiddle 来显示我的实际状态:http : //jsfiddle.net/Kienz/ujefxh7w/
按下ESC键后,“交互式绘图模式”被取消,多边形完成。但是现在多边形的位置是错误的(控件是正确的)。
有人有想法吗?
有没有人知道如何使用setBackgroundColor方法清除Fabric.js画布的背景颜色?
我基本上想回到"无背景颜色模式",所以它会显示背后的div.