Lighten svg part on hover without knowing original color

Viewed 2170

Ok, so I have made a piechart with angular and svg. It looks ok, but it is not really responding that well to hover events.

<path (click)="pieClick(cat)" class="slice" [attr.fill]="getColor(i)" [attr.d]="getArc()"></path>

That is the path that draws a pie slice. it should be noted here that the colors must be fetched from a backend server, so I cannot simply hardcode this into the css.

The css that I have right now looks like this

.slice {
    cursor: pointer;
}

.slice:hover {
    fill: #333;
}

And it works, but preferably I would like to just lighten the color on hover instead of setting it to #333.

Can this be done with pure CSS or do I need to somehow map that property to angular code?

2 Answers

You could use:

-webkit-filter: brightness(1.5);
-moz-filter: brightness(1.5);
-ms-filter: brightness(1.5);
filter: brightness(1.5);

You could potentially do it by creating a white div in front, and adding an alpha channel to make it partially transparent.

Try running the snippet below and see if it does what you need.

.box {
  width: 100px;
  height: 100px;
}
.box:hover::after {
  content: "";
  background-color: rgba(255,255,255,0.25);
  width: 100%;
  height: 100%;
  display: block;
}
.blue {
  background-color: blue;
}
.red {
  background-color: red;
}
.black {
  background-color: black;
}
.yellow {
  background-color: yellow;
}
<div class="box red"></div>
<div class="box blue"></div>
<div class="box black"></div>
<div class="box yellow"></div>

Related