[英]Transparent dynamic circular progress bar in JavaScript/CSS like hollow from inside or background image visible?
I achieved the circular progress bar with background color like this:我用这样的背景颜色实现了圆形进度条:
But when i try to use this same code but without background color it becomes PI or rectangular.但是当我尝试使用相同的代码但没有背景颜色时,它会变成 PI 或矩形。 I want to achieve like this:
我想这样实现:
But what i have is:但我所拥有的是:
If i try to remove bg color it becomes如果我尝试删除 bg 颜色,它会变成
I searched a lot but couldn't found any solution.我搜索了很多,但找不到任何解决方案。
Here is the code that i am using for this.这是我为此使用的代码。
<!-- Progress bar -->
<div class="bar-container">
<div class="circular-progress" style="background: conic-gradient(#FFCAF0 <?php echo $percentage * 3.6; ?>deg, #003866 5deg);">
<div class="value-container"><?php echo $percentage; ?>%</div>
</div>
</div>
Here is CSS code:这是 CSS 代码:
.bar-container {
background-color: #003866;
display: grid;
place-items: center;
}
.circular-progress {
position: relative;
height: 200px;
width: 200px;
border-radius: 50%;
display: grid;
place-items: center;
}
.circular-progress::before {
content: "";
display: block !important;
position: absolute;
height: 84%;
width: 84%;
background-color: #003866;
border-radius: 50%;
}
.value-container {
position: relative;
font-size: 20px;
color: #FFCAF0;
}
You can add clip-path
to “cut out” the inner circle.您可以添加
clip-path
以“剪切”内圈。
.bar-container { background-image: url('https://invent.kde.org/plasma/breeze/-/raw/6d4fe7781790c69758be380324262261699894f7/wallpapers/Next/contents/images/1024x768.png'); background-size: fill; background-position: center; background-repeat: no-repeat; display: grid; place-items: center; padding: 20px; }.circular-progress { position: relative; height: 200px; width: 200px; border-radius: 50%; display: grid; place-items: center; background-image: conic-gradient(#FFCAF0 120deg, transparent 5deg); clip-path: path('M20 100 a80 80 0 1 0 160 0 a80 80 0 1 0 -160 0 L0 100 L0 0 L200 0 L200 200 L0 200 L0 100 Z'); }.value-container { position: absolute; top: 100px; width: 100%; text-align: center; font-size: 20px; color: #FFCAF0; }
<div class="value-container">33 %</div> <div class="bar-container"> <div class="circular-progress"></div> </div>
You can move the background-image
property out of the CSS to edit it via PHP (but I guess you would have to use JavaScript to change it gradually).您可以将
background-image
属性移出 CSS 以通过 PHP 对其进行编辑(但我想您将不得不使用 JavaScript 逐渐更改它)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.