javascript 更改fabricjs中Rect的边框宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18910735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
change border width of Rect in fabricjs
提问by anam
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.
我使用 fabicjs 在画布上创建的这个矩形,现在在更改文本框时我想设置边框宽度。我试过,但它不工作。
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();
});
回答by Tom
I think your code is fine, don't know why it's not working. Check this http://jsfiddle.net/hellomaya/kNEaX/3/
我认为您的代码很好,不知道为什么它不起作用。检查这个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();
});