Day # 61: Circular progress
Progress bars are a very frequent feature in some websites. Especially when you are trying to describe certain services that are specialized in some fields, the visitor to our websites needs to be able to see how a particular business rates the services it provides.
They also represent a good opportunity to hone our CSS skills. With that in mind I decided to create for today’s website a circular progress bar. I had previously worked with others that were horizontal, so to make it circular was definitely a challenge. Fortunately, I found an innovative way to fill the progress of a circular bar thanks to Online Artist.
But first, I need to cover the issue of making an outer circle which hosts the progress bar. For that, one only need to play around with the before pseudo element:
.circular-progress::before {
content: "";
position: absolute;
height: 84%;
width: 84%;
background-color: #fff;
border-radius: 50%;
}
And finally, you need to fill that outer circle based on the progress by using the conic-gradient property:
let progress = setInterval(() => {
progressValue++
valueContainer.textContent = `${progressValue}%`
progressBar.style.background = `conic-gradient(
#4d5bf9 ${progressValue * 3.6}deg,
#cadcff ${progressValue * 3.6}deg
)`
if (progressValue == progressEndValue) {
clearInterval(progress)
}
}, speed)
Comments
Post a Comment