【问题标题】:Error on changing stroke or strokeWidth of rectangle, circle and Image in Fabric.js在 Fabric.js 中更改矩形、圆形和图像的笔画或笔画宽度时出错
【发布时间】:2016-10-01 01:03:54
【问题描述】:

我在更改矩形、圆形和图像的笔触颜色或笔触宽度时遇到错误。每次我更改这些值时,边框都会呈指数级增长。

var obj = canvas.getActiveObject();
obj.set("stroke", stroke);
obj.set("strokeWidth", strokeWidth);
canvas.renderAll();

我正在使用此代码来设置这些属性。

Image 1 shows the circle I added to canvas.

Image 2 shows the increased border after I change stroke color.

【问题讨论】:

  • 只有在我尝试设置 strokeWidth 时才会更新这种情况
  • 控件发疯了,我也尝试调整图像大小

标签: javascript html5-canvas fabricjs


【解决方案1】:

使用parseInt() 方法而不是直接设置它的值。

obj.set("stroke", parseInt(stroke));

【讨论】:

    【解决方案2】:

    不确定,但请尝试将内边距设置为 5-10 像素。

    obj.set("padding", '10');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-25
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多