2

this is my code

$("#textbackground").click(function() {

        var obj = canvas.getActiveObject();
    ![enter image description here][1]
    //alert("weight");
    if (!obj) return;

    obj.setTextBackgroundColor('rgb(0,200,0)');

    canvas.renderAll();
    });

i have to do set the background color to text only, following like this link , but i am getting background color to text in square, not for text only enter link description here

so how do i set the

obj.setTextBackgroundColor('rgb(0,200,0)');
4

3 回答 3

7

使用fabric.Object set(key, value)函数。

obj.set('backgroundColor', 'rgb(0,200,0)');
于 2013-09-07T12:53:44.203 回答
4
var obj = canvas.getActiveObject();

if (obj.isType('text')) {
    obj.textBackgroundColor = "#ccc"; // or obj.backgroundColor = "#ccc";
    canvas.renderAll();
}
于 2013-09-09T07:01:17.660 回答
-4

尝试使用类似.css()的属性background-color

obj.css('background-color', 'rgb(0,200,0)');

或者你可以直接给颜色

obj.css('background-color', 'red');
于 2013-09-07T12:35:58.473 回答