纯css实现div背景色从左到右的刷动效果

在这里插入图片描述
动画主要靠这个部分实现

@keyframes LeftToRight {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}
//使用
{
   animation: LeftToRight 3s infinite;
}

具体代码如下

        <div class="text">
          <p>设备接入</p>
          <div>
            <img src="../../../assets/image/icon_equip.png" />
            <span class="number">
              <p class="unit">个</p>
              <span class="num">12.8</span>
              万
            </span>
          </div>
        </div>
      </el-button>
      <style>
      .el-button {
      position: relative;
      width: 28%;
      height: 45%;
      padding: 0;
      background: rgba(255, 255, 255, 0.08);
      border-radius: 8px;
      border: 1px solid rgba(255, 255, 255, 0.16);
      color: #fff;
      margin: 2% 1.5% 0 1.5%;
      font-size: 12px;

      .text {
        width: 76%;
        font-size: 12px;
        color: #fff;
        text-align: left;
        position: absolute;
        z-index: 2;
        top: 12%;
        left: 10%;

        p {
          margin: 0 auto 30% 0;
          line-height: 20px;
          text-align: left;
        }
        .unit {
          text-align: right;
          margin-bottom: 12px;
        }
        .number {
          font-size: 12px;
          position: absolute;
          bottom: 2px;
          right: -2px;
        }
        .num {
          font-size: 15px;
        }
        img {
          height: 28px;
        }
        img.large {
          height: 34px;
          margin-bottom: -3px;
        }
      }
}
    .el-button::after {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      right: 0;
      transition: 0.3s;
      opacity: 0.3;
      background: rgba(0, 0, 0, 0.8);
      transform-origin: left;
      animation: LeftToRight 3s infinite;
    }

    .el-button:hover::after {
      transform: scaleX(1);
    }
@keyframes LeftToRight {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}
</style>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值