Fabric.js - Transparent background on circle shape with stroke/border

Simon picture Simon · Nov 18, 2015 · Viewed 15.6k times · Source

I have a circle being rendered in fabric.js version 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
});

I want to set the background as transparent but retain the stroke around the circle. Is this possible in fabric.js? The opacity is also being applied to the stroke/border, I am trying to apply it to the background of the circle only.

I have tried this as well with a transparent background, still no luck:

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

Answer

Guy picture Guy · Nov 18, 2015

You can set 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)'
});

JSFiddle