【问题标题】:How to animate the filling of a html element如何动画填充html元素
【发布时间】:2016-09-15 18:56:22
【问题描述】:

所以我遇到的问题是我正在尝试为圆形 html 元素的填充设置动画。圆圈开始是灰色的,用户将提供一个数字,圆圈将通过另一个蓝色圆圈填充到用户指定的原始圆圈的百分比来改变颜色。我无法弄清楚如何动画或创建蓝色圆圈的填充。

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;
}

所以我有 3 个圆圈,一个仅用于黑色边框,一个仅显示灰色边框,第三个是第三个圆圈,我将使用动画来充当我堆叠的“蓝色填充”它们彼此重叠,以使其具有表盘填充的效果。同样,我只是不确定如何制作动画,有没有办法只显示蓝色圆圈的一部分并不断显示更多,直到它显示整个蓝色圆圈?感谢您的帮助。我正在一个 angularjs 应用程序中编写此代码,但尚未编写 angularjs 代码。

【问题讨论】:

    标签: javascript html css angularjs css-transitions


    【解决方案1】:

    我稍微简化了您的解决方案。而不是 3 个 DIV,只有 2 个。

    外层DIV画圆并说“我的孩子不能溢出”。

    内部 DIV 是一个简单的矩形。他是你动画的那个人,从底部开始上下移动他。

    就像在船上看舷窗一样!

    .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>

    【讨论】:

    • 如果不清楚我在做什么,请删除overflow: hidden; 以从“不同的角度”查看。
    • 很好的答案!我可以用我的 javascript 来使用它,它就像一个魅力
    • @LukeFlournoy 很高兴它成功了。不要忘记将其标记为已回答。放轻松!
    猜你喜欢
    • 1970-01-01
    • 2015-02-03
    • 1970-01-01
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 2016-04-15
    • 2020-09-07
    • 2015-08-07
    相关资源
    最近更新 更多