Here is a jsfiddle: https://jsfiddle.net/pgckezw7/3/
Basically, it works fine with 1 color, but not with 2 colors.
With 2 colors, the problem is if the first percentage is <= 50, then the second percentage will not go past 50 even if the sum of the two colors is > 50. (shown in the 1st circle in jsfiddle)
But with 2 colors, if the first percentage is > 50, it works just as expected (shown in the 2nd and 3rd circles in the jsfiddle)
To show the 2nd color I added the class left-side-2.
$progress(percentage1) and $snapSize(percentage2) are the two percentages that need to be in different colors.
The main logic is inside of draw-progress mixin, at the bottom of the jsfiddle, I looped over the class names for progress-(percentage1)-(percentage2)
Any help or hint is appreciated, maybe the approach I've taken is wrong? Thanks in advance.
Here is the code:
HTML:
progress-45-50, doesn't work because percentage1(45) less than 50, which will only add up to 50 total. 45 <= 50 && 45 + 50 > 50, which will only render 45-5.
progress-51-20, works, because percentage1(51) greater than 50.
<div class="pie-wrapper progress-45-50 style-2">
<span class="label">45<span class="smaller">%</span></span>
<div class="pie">
<div class="left-side-2 half-circle"></div>
<div class="left-side half-circle"></div>
<div class="right-side half-circle"></div>
</div>
<div class="shadow"></div>
</div>
SCSS:
@mixin draw-progress($progress, $color, $snapSize, $snapColor) {
.pie {
.half-circle {
border-color: $color;
}
.left-side-2 {
transform: rotate(($progress + $snapSize) * 3.6deg);
border-color: $snapColor;
}
.left-side {
transform: rotate($progress * 3.6deg);
}
@if $progress + $snapSize > 50 and $progress <= 50 {
.right-side {
display: none;
}
}
@if $progress <= 50 {
.right-side {
display: none;
}
} @else {
clip: rect(auto, auto, auto, auto);
.right-side {
transform: rotate(180deg);
}
}
}
}
I hope to get some help with my draw-progress in scss, this part
@if $progress + $snapSize > 50 and $progress <= 50 {
.right-side {
display: none;
}
}
question from:
https://stackoverflow.com/questions/65856733/css-circular-progress-bar-adding-second-color