Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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',
    });
like image 725
Simon Avatar asked Nov 18 '15 16:11

Simon


2 Answers

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

like image 110
Guy Avatar answered Nov 17 '22 02:11

Guy


Another option is to use 'transparent' value in fill

const rect = new fabric.Rect({
  top: 10,
  left: 10,
  width: 50,
  height: 50,
  hasBorder: true,
  stroke: 'yellow',
  strokeWidth: 3,
  fill:'transparent'
});
like image 31
Dat Avatar answered Nov 17 '22 04:11

Dat