8.纯 CSS 创作一个充电 loader 特效

原文地址:https://segmentfault.com/a/1190000014669547

右边多出来的是 :after 的border 

HTML代码:

<div class="battery"></div>

CSS代码:

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    display:flex;
    justify-content: center;
    align-items: center;
    /*background: linear-gradient(to bottom, teal, aqua); */
}
.battery{
    width: 6em;
    height: 3em;
    color: midnightblue;
    border: 0.5em solid currentColor;
    border-radius: 0.2em;
    font-size: 2em;
    position: relative;
    /* 充电颜色 */
    background-image: linear-gradient(to right, green, green);
    background-repeat: no-repeat;
     /* 充电图像大小 */
    background-size: 30% 80%;
    /* 给内部充电图像定位  */
    background-position: top 0.3em left 0.3em;
    animation: charge 5s steps(8) infinite;
}
.battery::after{
    position: absolute;
    content: '';
    width: 0.5em;
    height: 2em;
    background-color: currentColor;
    top: 0.5em;
    right: -1em;
    border-radius: 0 0.2em 0.2em 0;
}
@keyframes charge {
    from {
        background-size: 10% 80%;
    }
    to {
        background-size: 95% 80%;
    }
}

 

posted on 2018-12-13 19:55  人生与戏 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/FlyingLiao/p/10116030.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值