【问题标题】:circle progress bar css圆形进度条css
【发布时间】:2018-11-17 06:04:30
【问题描述】:

我想创建一个圆条,随着它的进行,笔划会变得越来越粗。
是否可以使用可以在 ionic 移动应用上运行的 css 或 svg。

这是我想要实现的目标:

这里是fiddle 的起点:

.wrap {
  background: #0b1626;
  padding: 2em;
  color: #FFF;
  font-family: 'Arial Black';
}
.knob {
  position: relative;
  margin: 0 auto;
  padding: 1.5em;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  border: 1px solid #e84d51;
}
.knob .val {
  padding-top: 1em;
  font-size: 28px;
  text-align: center;
}
<div class="wrap">
  <div class="knob">
    <div class="stats">
      <p class="val">16,858<br>1,285</p>
    </div>
  </div>
</div>

【问题讨论】:

  • 圆应该如何动画?是不是应该转圈圈?
  • 它应该从 0 到 100% 顺时针方向,一旦到达起点就应该停止
  • @Saqueib 这没有回答问题。请提供显示动画状态为 0%、50% 和 100% 的插图。
  • 对于基本的 HTML 和 CSS 是否可能存在疑问,因为没有任何方法可以沿路径为圆形边框宽度设置动画。如果没有附加大量的 Javascript,即使 SVG 也可能会出现问题。因此,这个问题对于这个问题来说可能太宽泛了。
  • @Saqueib 我想我们都知道普通的圆形进度表是什么样子的。你要求不同的东西,但到目前为止你还没有充分解释你想要达到的目标。请参阅我之前的评论。

标签: css svg ionic css-shapes


【解决方案1】:

这是我的尝试。有很多 div,但我没有时间尝试减少它们。

基本上,它在一个圆圈和另一个圆圈之间使用偏移量。

.container {
  width: 400px;
  height: 400px;
  position: relative;
  background-color: black;
}

.left {
  position: absolute;
  width: 50%;
  height: 100%;
  right: 0px;
  overflow: hidden;
}

.moving {
  animation: rotatel 8s 1s linear forwards; /* to keep both animations the same */
}

.left .moving {
  position: absolute;
  width: calc(200% - 70px);
  height: calc(100% - 70px);
  right: 15px;
  top: 20px;
  border: 20px solid transparent;
  border-top-color: red;
  border-right-color: red;
  border-radius: 50%;
  transform: rotate(-135deg);
}

@keyframes rotatel {
   from {transform: rotate(-135deg);}
   50%, 100% {transform: rotate(45deg);}
}

.right {
  position: absolute;
  width: 50%;
  height: 100%;
  left: 0px;
  overflow: hidden;
}

.right .moving {
  position: absolute;
  width: calc(200% - 50px);
  height: calc(100% - 50px);
  left: 10px;
  top: 0px;
  border: 20px solid transparent;
  border-top-color: red;
  border-right-color: red;
  border-radius: 50%;
  transform: rotate(45deg);
  animation-name: rotater;
}

@keyframes rotater {
   0%, 50% {transform: rotate(45deg);}
   100% {transform: rotate(225deg);}
}
.inner {
  position: absolute;
  width: calc(100% - 40px);
  height: calc(100% - 40px);
  border-radius: 50%;
  background-color: white;
  left: 20px;
  top: 20px;
  border: red solid 1px;
  background-color: black;
}
<div class="container">
<div class="left">
    <div class="moving"></div>
</div>
<div class="right">
    <div class="moving"></div>
</div>
<div class="inner"></div>
</div>

顺便说一下,一个关于在 div 中使用边框和伪元素实现底层形状的示例

.test1 {
  width: 400px;
  height: 400px;
  border: 1px solid red;
  border-top-width: 1px;
  border-right-width: 10px;
  border-bottom-width: 20px;
  border-left-width: 30px;
  border-radius: 50%;
  position: relative;
  margin: 40px;
}

.test1:after {
  content: "";
  position: absolute;
  width: 50%;
  height: 50%;
  border: 0px solid green;
  border-left-width: 30px;
  border-top-width: 40px;
  border-radius: 100% 0px 0px 0px;
  position: absolute;
  top: -40px;
  left: -30px;
}
&lt;div class="test1"&gt;&lt;/div&gt;

【讨论】:

  • 看起来很酷,只是想让动画在到达起点后停止
  • 只需从动画中删除 infinite。它只会执行一次
  • 不错的一个。不过,我对动画的理解并不相同。
  • @web-tiki 谢谢!是的,这个问题(如 cmets 中所述)没有得到很好的解释。
  • 稍微改变了 sn-p。现在它只运行一次,并且有点延迟。我也把动画属性统一到了一点,改起来更方便