在fabric.js中更改对象的选择样式

时间:2013-08-30 06:35:37

标签: javascript jquery html fabricjs

我在我的项目中使用了面料插件。当选择了对象时,我们选择了具有以下设计的区域。我可以将图像附加到选定区域,如下图所示: -

我使用

设置文字
hw[i] = new fabric.Text($(this).val(), {
                left : 100,
                top : 100,
                fontSize : 20
            });

目前,我正在:

enter image description here

我希望得到,

enter image description here

谢谢,

1 个答案:

答案 0 :(得分:1)

虽然你不能直接用Fabric JS做到这一点,但有人为它做了一个扩展:

GitHub网站:https://github.com/pixolith/fabricjs-customise-controls-extension

现场演示:http://pixolith.github.io/fabricjs-customise-controls-extension/example/index.html

这将允许您分配更改句柄图像及其操作。

添加扩展程序后,您可以添加以下内容:获取操作

fabric.Canvas.prototype.customiseControls({
    tl: {
        action: 'remove',
    },
    tr: {
        action: 'rotate'
    },
    br: {
        action: 'scaleY',
    },
});

然后用:

更改图标
fabric.Object.prototype.customiseCornerIcons({
    settings: {
        borderColor: 'black',
        cornerSize: 25,
        cornerShape: 'circle',
        cornerBackgroundColor: 'black',
        cornerPadding: 10
    },
    tl: {
        icon: 'icon/trashcan.svg'
    },
    tr: {
        icon: 'icon/rotate.svg'
    },
    br: {
        icon: 'icon/scale.svg'
    },
});
相关问题