如何更改 fabric.js 上的默认 selectionColor?

How to change the default selectionColor on fabric.js?

如何更改 fabric.js 上的默认蓝色 selectionColor?我试图在 fabric.js 中更改这些行但没有效果:

selectionColor: 'rgba(17,119,255,0.3)',
selectionBorderColor:   'rgba(255, 255, 255, 0.3)',
editingBorderColor: 'rgba(102,153,255,0.25)',

还有其他方法吗?

您可以使用此参数更改织物对象的边框颜色(当您 select 对象时显示):borderColor

例如:

canvas._objects[0].set({'borderColor':'#fbb802'});
canvas.renderAll();

希望有所帮助,祝你好运。

好的,现在我明白您的确切需求了,您想要更改所选分组对象的边框,也许还想更改边框上的方块。

我在厨房水槽上测试了它,它可以工作, 您必须捕获选择事件,并在事件中更改 activeGroup[=24] 的 borderColorcornerColor 属性=].

您的 object:selected 活动:

canvas.on('object:selected', function(o){
var activeObj = o.target;
if(activeObj.get('type') == 'group') {
     activeObj.set({'borderColor':'#fbb802','cornerColor':'#fbb802'});

 }
});

希望有所帮助,祝你好运。

使用selectionBorderColor属性。

canvas.selectionBorderColor = 'red';

欲了解更多信息,请访问:http://fabricjs.com/customization

找了好久终于找到了在选择多个对象时更改默认格式样式的解决方案。

fabric.Object.prototype.set({     
      transparentCorners: false,
      cornerStyle: 'circle',
      cornerColor: '#3880ff',
      cornerSize: 12,
    })