So, I have a few different progress bars on this page - http://kaye.at/play/goals
Here's my HTML & CSS:
<div class="meter"><span style="width: 100%;"></span></div>
.meter {
height: 5px;
position: relative;
background: #f3efe6;
z-index: 0;
margin-top: -5px;
overflow: hidden;
}
.meter > span {
z-index: 50;
display: block;
height: 100%;
background-color: #e4c465;
position: relative;
overflow: hidden;
}
I want to simply animate the progress bar so that it slowly goes up from 0% to whatever percentage it's at, rather than just appearing there, but I'd like to do it in the simplest way possible. What's my best option and is it possible with the current code I'm using?
The only way I can think to animate to your width set inline is to add another
span
, so the HTML ends up as:That extra span is needed, as we have no way (using just CSS) of checking what the inline style wants the width to be and so animating to it. And unfortunately we can't animate to
auto
.The CSS (you'll need to add the necessary prefixes):
You can see this in action here. Browsers that don't support CSS animations will just get the bar in its final state.
I developed a progress bar so that it's so light and neat right now and you have percentage value too, I applied CSS transition when the percentage changes from 100% to 7%, just click on the
Change
button to see how it works. Changetransition: width 3s ease;
from 3s to whatever fits your need for slower or faster transition.