Fabric.js-圆形的透明背景与中风/边框

Sim*_*mon 8 javascript fabricjs

我在fabric.js版本1.6.0-rc.1中渲染了一个圆圈:

var circlePatrol = new fabric.Circle({
  top: 300,
  left: 180,
  radius: 200,
  strokeDashArray: [10, 10],
  stroke: 'black',
  strokeWidth: 10,
  fill: 'white',
  opacity: 0.2
});
Run Code Online (Sandbox Code Playgroud)

我想将背景设置为透明但保留围绕圆圈的笔划.这在fabric.js中是否可行?不透明度也应用于笔触/边框,我试图将其应用于圆的背景.

我也试过透明的背景,但仍然没有运气:

var circlePatrol = new fabric.Circle({
      top: 300,
      left: 180,
      radius: 200,
      strokeDashArray: [10, 10],
      stroke: 'black',
      strokeWidth: 10,
      backgroundColor: 'transparent',
    });
Run Code Online (Sandbox Code Playgroud)

Guy*_*Guy 15

你可以设置fill: 'rgba(0,0,0,0)'.

var circlePatrol = new fabric.Circle({
  top: 0,
  left: 0,
  radius: 200,
  strokeDashArray: [10, 10],
  stroke: 'black',
  strokeWidth: 10,
  fill: 'rgba(0,0,0,0)'
});
Run Code Online (Sandbox Code Playgroud)

的jsfiddle


Dat*_*yen 6

另一种选择是在填充中使用“透明”值

const rect = new fabric.Rect({
  top: 10,
  left: 10,
  width: 50,
  height: 50,
  hasBorder: true,
  stroke: 'yellow',
  strokeWidth: 3,
  fill:'transparent'
});
Run Code Online (Sandbox Code Playgroud)