Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change border width of Rect in fabricjs

This Rectangle i have created on canvas using fabicjs , now on change of text box i want to set border width . i tried following but its not working.

image[img] = new fabric.Rect({
                    top : 100,
                    left : 100,
                    width : 50,
                    height : 50,
                    fill : '#f55',
                    stroke : 'black',
                    strokeWidth : 1
                });

Changing Border Width ::

$('#shape_border_size').change(function() {
    console.log(' size changed to ' + $(this).val());

    var obj = canvas.getActiveObject();

    if (!obj)
        return;

    //obj.set('strokeWidth', $(this).val());
    canvas.renderAll();

});
like image 717
anam Avatar asked Sep 20 '13 07:09

anam


1 Answers

I think your code is fine, don't know why it's not working. Check this http://jsfiddle.net/hellomaya/kNEaX/3/

var rect = new fabric.Rect({
    top: 100,
    left: 100,
    width: 50,
    height: 50,
    fill: '#f55',
    stroke: 'white',
    strokeWidth: 1
});

canvas.add(rect);
canvas.renderAll();

$('#a').click(function () {
    rect.set('strokeWidth', 20);
    canvas.renderAll();
});

$('#b').click(function () {
    rect.set('strokeWidth', 20);
    rect.width += 20;
    rect.height += 20;
    canvas.renderAll();
});
like image 105
Tom Avatar answered Oct 22 '22 11:10

Tom