I'm trying to make an animated semi-circle skill bar, based only CSS and JS (no jQuery or other frameworks).
Here is a really bad MS Paint drawing example:
The blue part of the skill bar needs to animate on page load, and the percentage animation counts up from 0.
Both the percentage number and the amount of blue skill bar need be set inside the HTML. And the whole thing needs to be responsive.
I started creating the design as normal skill bar, but for the life of me I can't figure out how to curve it into a semi-circle.
let start // set on the first step to the timestamp provided
const el = document.getElementById('count') // get the element
const final = parseInt(el.textContent, 10) // parse out the final number
const duration = 2000 // duration in ms
const step = ts => {
if (!start) {
start = ts
}
// get the time passed as a percentage of total duration
let progress = (ts - start) / duration
el.textContent = Math.floor(progress * final) // set the text
if (progress < 1) {
// if we are not 100% complete, request another animation frame
requestAnimationFrame(step)
}
}
// start the animation
requestAnimationFrame(step)
.outerbar {
width: 100%;
height: 20px;
background-color: #eee;
border-radius: 100px;
}
.bar {
background: #1565C0;
border-radius: 100px;
height: 100%;
transition: width 1s linear;
float: left;
min-width: 30px;
}
.text-label {
font-size: 14px;
text-align: center;
}
.percent-label {
float: right;
margin-right: 5px;
font-size: 12px;
line-height: 1.7em;
}
/* Animate the blue skill bar on page load */
@-webkit-keyframes bar {
0% {
width: 0;
}
}
@-moz-keyframes bar {
0% {
width: 0;
}
}
@keyframes bar {
0% {
width: 0;
}
}
.bar {
-webkit-animation: bar 2s ease-in-out;
-moz-animation: bar 2s ease-in-out;
animation: bar 2s ease-in-out;
}
<div class="outerbar">
<div class="bar" style="width: 40%;">
<div class="percent-label"><span id="count">40</span>%</div>
</div>
</div>
<div class="text-label">Total Score</div>