0

So the problem I have is I am trying to animate the filling of a circle html element. The circle starts out grey, the user will provide a number and the circle will change color by having another blue circle fill up to the percentage of the original circle specified by the user. I am having trouble figuring out how to animate, or create, the filling of the blue circle.

HTML

<div class="circle circle-outer-border">
    <div class="circle circle-background">
        <div class="circle circle-fill"></div>
    </div>
</div>

CSS

.circle{
  height: 200px;
  width: 200px;
  -moz-border-radius: 100px;
  -webkit-border-radius: 100px;
}

.circle-outer-border{
  border: 1px solid black;
}

.circle-background{
  border: 20px solid #b1b1b1;
  background-color: transparent;
  margin-left: -1px; margin-top: -1px /** to make up for outer-border        margin**/
}

.circle-fill{
  border: 20px solid #147fc3;
  background-color: transparent;
  margin-left: -21px; margin-top: -21px;
}

So I have 3 circles, one for just the black border, one that just shows the grey border and a third one that is the third circle which is the one I will animate to act as a 'blue fill' I have stacked them on top of each other in order to give it the effect of a dial filling. Again I'm just not sure how to do the animation, is there a way to just show a portion of the blue circle and continually show more until it shows the whole blue circle? Thank you for the help. I am writing this in a angularjs app, but have not written the angularjs code yet.

Luke Flournoy
  • 3,393
  • 2
  • 16
  • 22

1 Answers1

0

I simplified your solution just a bit. Instead of 3 DIVs, there are just 2.

The outer DIV draws the circle and says "my children cannot overflow".

The inner DIV is a simple rectangle. He is the one you animate, starting from the bottom and moving him up and down.

Exactly like looking out a porthole on a boat!

.circle{
  height: 200px;
  width: 200px;
}
.circle-outer-border{
  position: relative;
  border: 1px solid black;
  border-radius: 100px;
  -moz-border-radius: 100px;
  -webkit-border-radius: 100px;
  overflow: hidden;
}

.circle-fill{
  position: absolute;
  top: 0;
  left: 0;
  background-color: #147fc3;
}

.animated .circle-fill {
  -webkit-animation: fillerup 5s infinite;
  animation: fillerup 5s infinite;
}
.static .circle-fill {
  top: 150px;
}

@-webkit-keyframes fillerup {
  0% {
    top: 200px;
  }
  100% {
    top: 0px;
  }
}
@keyframes fillerup {
  0% {
    top: 200px;
  }
  100% {
    top: 0;
  }
}
<div class="circle circle-outer-border animated">
  <div class="circle circle-fill"></div>
</div>
<br/>
<div class="circle circle-outer-border static">
  <div class="circle circle-fill"></div>
</div>
Nate
  • 1,268
  • 13
  • 20