Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make shapes with opacity, but not the border in konvajs

I am using konvajs for drawing on canvas. I just found a opacity property, where I can set the opacity of the whole shape (in my case a closed line) to the alpha value, but that also includes the border and not just the filling opacity.

  new Konva.Line({
    points: [30, 20, 49, 54, 100, 220],
    fill: 'red',  // put an opacity just on this color
    stroke: 'black',
    strokeWidth: 2,
    closed : true,
    opacity: 0.4
  });

Is there a possibility to just make the filling with some opacity and keep the border totally visible?

like image 571
Safari Avatar asked Oct 26 '25 15:10

Safari


1 Answers

Just use rgba for fill:

new Konva.Line({
  points: [30, 20, 49, 54, 100, 220],
  fill: 'rgba(255,0,0,0.4)',
  stroke: 'black',
  strokeWidth: 2,
  closed : true
});
like image 76
lavrton Avatar answered Oct 29 '25 05:10

lavrton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!