fabricjs - 如何在fabricjs中获取对象的所有属性?

标签 fabricjs

我想知道如何在fabricjs中获取对象的所有属性? .
我必须将这些属性应用于另一个对象(我不想克隆)。
请帮我。

最佳答案

I have found answer for my own question.

<canvas id="canvas" width="300" height="300"></canvas> <br/>
<button id="replace"> Replace </button> 
<span id="message"></span>

var canvas = ctx = activeObject = text1 = text2 = '';
var textProperties = ['angle', 'backgroundColor', 'clipTo', 'fill', 'fillRule', 'flipX', 'flipY', 'fontFamily', 'fontSize', 'fontStyle', 'fontWeight', 'globalCompositeOperation', 'height', 'id', 'left', 'letterSpace', 'lineHeight', 'opacity', 'originX', 'originY', 'path', 'scaleX', 'scaleY', 'shadow', 'stroke', 'strokeDashArray', 'strokeLineCap', 'strokeLineJoin', 'strokeMiterLimit', 'strokeWidth', 'text', 'textAlign', 'textBackgroundColor', 'textDecoration', 'top', 'transformMatrix', 'useNative', 'visible', 'width'];

console.clear();
canvas = new fabric.Canvas('canvas');
ctx = canvas.getContext('2d');

text1 = new fabric.Text('Text1', {
    fill: 'red',
    left: 50,
  top: 50
});

text2 = new fabric.Text('Text2', {
    fill: 'green',
    left: 150,
  top: 50
});

canvas.add(text1, text2).renderAll().setActiveObject(text1);
activeObject = canvas.getActiveObject();

$(document).on('click', '#replace', function(e) {
    e.preventDefault();

  for(var i=0; i<textProperties.length; i++) {
    var property = textProperties[i];
    text2.set(property, activeObject.get(property));
  }
  $("#message").css({ 'display':'block' }).html('Success..!');
  canvas.renderAll().setActiveObject(text2);
});

https://jsfiddle.net/mullainathan/coLcz0zx/

关于fabricjs - 如何在fabricjs中获取对象的所有属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36419801/

相关文章:

javascript - 使用 fabricjs 模拟自由绘图

html5-canvas - 在 Fabric.js 中克隆对象

javascript - fabric js 作为 ES6 在 Chrome 中的导入不起作用

javascript - Fabric.js toJSON() 方法缺少图像

javascript - Fabric.js 基于svg的多重裁剪

javascript - fabricjs 将图像设置为背景

javascript - 如何在fabric js堆栈中的图像顶部添加文本?

json - 为fabric.js中的一些对象分配对象标识符并保存为json

javascript - Fabric.js - 色调过滤器

javascript - 如何使用 Fabricjs 自由绘制椭圆?