I have a circular progress bar that animates when the page loads, but I want it to animate when the user scrolls down to it. If the page loads, the user does not see the animation because the animation runs and finishes once they enter or reload the page.
This is my code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
#skill-body{
padding: 10px;
min-height: 80vh;
color: #F0505C;
background: #191315;
}
.skill-wrapper{
max-width: 1100px;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
margin: auto;
display: flex;
}
.skill-wrapper .card{
width: calc(100% / 2);
height: 300px;
display: flex;
align-items: center;
justify-content: space-evenly;
flex-direction: column;
margin: auto;
}
.skill-wrapper .card .circle{
position: relative;
height: 150px;
width: 150px;
border-radius: 50%;
}
.skill-wrapper .card .circle .box{
height: 100%;
width: 100%;
transform: translate(-50%, -50%) scale(0.9);
border-radius: 50%;
}
.skill-wrapper .card .circle:hover .box{
transform: translate(-50%, -50%) scale(1.19)
}
.skill-wrapper .card .circle .box,
.skill-wrapper .card .circle .box span{
position: absolute;
top: 50%;
left: 50%;
transition: all 0.1s;
}
.skill-wrapper .card .circle .box span{
font-size: 30px;
transform: translate(-50%, -50%);
}
.skill-wrapper .card .text{
font-size: 20px;
}
</style>
<div class="sec" id="skill-body">
<div class="skill-wrapper">
<div class="card">
<div class="circle">
<div class="bar" data-thickness="8"></div>
<div class="box"><span>78%</span></div>
</div>
<div class="text">Illustrator</div>
</div>
<div class="card ps">
<div class="circle">
<div class="bar" data-thickness="8"></div>
<div class="box"><span>76%</span></div>
</div>
<div class="text">Photoshop</div>
</div>
</div>
<script>
let options = {
startAngle: -1.55,
size: 150,
value: 0.78,
fill: {color: "#F0515C"}
}
$(".circle .bar").circleProgress(options).on('circle-animation-progress', function(event, progress, stepValue){
$(this).parent().find("span").text(String(stepValue.toFixed(2).substr(2)) + "%")
});
$(".ps .bar").circleProgress({
value: 0.76,
});
</script>
</div>