CSS circle-progress-bar

时间:2017-07-27 19:48:50

标签: css

我想在https://bootsnipp.com/snippets/featured/circle-progress-bar处使用进度条,但是如果您有2,3或更多类型(每个都有不同的百分比),我不知道如何设置低于50%这些在你的网站上,因为这个代码设置了你到达那里的每种类型的酒吧的右侧,我不知道该怎么做,当我只想在3岁时不到50%。

栏的类型:

 .progress .progress-right .progress-bar{
    left: -100%;
    border-top-left-radius: 80px;
    border-bottom-left-radius: 80px;
    border-right: 0;
    -webkit-transform-origin: center right;
    transform-origin: center right;
    animation: loading-1 1.8s linear forwards;
}

+

    @keyframes loading-1{
    0%{
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    100%{
        -webkit-transform: rotate(180deg);
        transform: rotate(180deg);
    }
有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:2)

使用SVG

svg {
  transform: rotate(-90deg);
  stroke-dasharray: 251; /* (2PI * 40px) */
  stroke-dashoffset: 251;
  animation: offsettozero 5s linear forwards;
}

@keyframes offsettozero {
  to {
    stroke-dashoffset: 0;
  }
}
<svg height="100" width="100">
 <circle cx="50" cy="50" r="40" stroke="#428bca" stroke-width="6" fill="#333" />
</svg> 

答案 1 :(得分:1)

由于右侧动画在所有进度圈之间共享,如果您想制作一个小于50%的动画,则必须覆盖该通用样式。然后你不需要左侧动画。

所以你的CSS会是这样的:

.progress.yourDiv .progress-right .progress-bar {
  animation: yourAnimation 1.8s linear forwards;
}
.progress.yourDiv .progress-left .progress-bar{
  animation: none;
}

其中yourAnimation与Bootstrap示例中.progress .progress-right .progress-bar的共享权限规则相同,但名称已更改。

对于37.5%的动画,yourAnimation看起来像这样:

@keyframes yourAnimation{
    0%{
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    100%{
        -webkit-transform: rotate(135deg);
        transform: rotate(135deg);
    }
}

以下是一个示例,.yourDiv.yellowyourAnimationloading-3

&#13;
&#13;
.progress {
  width: 150px;
  height: 150px !important;
  float: left;
  line-height: 150px;
  background: none;
  margin: 20px;
  box-shadow: none;
  position: relative;
}
.progress:after {
  content: "";
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 12px solid #fff;
  position: absolute;
  top: 0;
  left: 0;
}
.progress>span {
  width: 50%;
  height: 100%;
  overflow: hidden;
  position: absolute;
  top: 0;
  z-index: 1;
}
.progress .progress-left {
  left: 0;
}
.progress .progress-bar {
  width: 100%;
  height: 100%;
  background: none;
  border-width: 12px;
  border-style: solid;
  position: absolute;
  top: 0;
}
.progress .progress-left .progress-bar {
  left: 100%;
  border-top-right-radius: 80px;
  border-bottom-right-radius: 80px;
  border-left: 0;
  -webkit-transform-origin: center left;
  transform-origin: center left;
}
.progress .progress-right {
  right: 0;
}
.progress .progress-right .progress-bar {
  left: -100%;
  border-top-left-radius: 80px;
  border-bottom-left-radius: 80px;
  border-right: 0;
  -webkit-transform-origin: center right;
  transform-origin: center right;
  animation: loading-1 1.8s linear forwards;
}
.progress .progress-value {
  width: 90%;
  height: 90%;
  border-radius: 50%;
  background: #44484b;
  font-size: 24px;
  color: #fff;
  line-height: 135px;
  text-align: center;
  position: absolute;
  top: 5%;
  left: 5%;
}
.progress.blue .progress-bar {
  border-color: #049dff;
}
.progress.blue .progress-left .progress-bar {
  animation: loading-2 1.5s linear forwards 1.8s;
}
.progress.yellow .progress-bar {
  border-color: #fdba04;
}
.progress.yellow .progress-right .progress-bar {
  animation: loading-3 1.8s linear forwards;
}
.progress.yellow .progress-left .progress-bar {
  animation: none;
}
@keyframes loading-1 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(180deg);
    transform: rotate(180deg);
  }
}
@keyframes loading-2 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(144deg);
    transform: rotate(144deg);
  }
}
@keyframes loading-3 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(135deg);
    transform: rotate(135deg);
  }
}
&#13;
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>


<div class="progress blue">
  <span class="progress-left">
                    <span class="progress-bar"></span>
  </span>
  <span class="progress-right">
                    <span class="progress-bar"></span>
  </span>
  <div class="progress-value">90%</div>
</div>

<div class="col-md-3 col-sm-6">
  <div class="progress yellow">
    <span class="progress-left">
                    <span class="progress-bar"></span>
    </span>
    <span class="progress-right">
                    <span class="progress-bar"></span>
    </span>
    <div class="progress-value">37.5%</div>
  </div>
</div>
&#13;
&#13;
&#13;