有趣的css - 列表块加载动效

大家好,我是 Just,这里是「设计师工作日常」,今天分享的是用 css 打造一个极简的列表块加载动效。

最新文章通过公众号「设计师工作日常」发布。


整体效果

💎知识点:
1️⃣ animation 动画
2️⃣ flex 布局
3️⃣ opacity 透明属性

🔑思路:
写好列表块整体布局,然后利用不同的动画时长调整变化透明度,来实现视觉上的列表正在加载的效果。

适用于 app 列表加载延迟等页面场景。


核心代码部分,简要说明了写法思路;完整代码在最后,可直接复制到本地运行。

核心代码

html 代码

<div class="list-box70">
  <div class="pic70"></div>
  <div class="list70">
    <span class="span70"></span>
    <div class="span-div70">
      <span class="span701"></span>
      <span class="span702"></span>
    </div>
  </div>
</div>

html 搭建列表块整体布局。

css 部分代码

.list-box70{
  width: 200px;
  height: 76px;
  position: relative;
  background-color: #f8f8f8;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  box-sizing: border-box;
}
.pic70{
  width: 44px;
  height: 44px;
  position: relative;
  background-color: #e4e4e4;
  border-radius: 4px;
  animation: eff70 1.8s linear infinite;
}
.list70{
  position: relative;
  display: flex;
  flex-direction: column;
  margin-left: 10px;
}
.span70{
  width: 114px;
  height: 20px;
  position: relative;
  border-radius: 4px;
  background-color: #e4e4e4;
  animation: eff70 2s linear infinite;
}
.span-div70{
  position: relative;
  margin-top: 10px;
  display: flex;
}
.span701,.span702{
  width: 65px;
  height: 14px;
  position: relative;
  border-radius: 4px;
  background-color: #e4e4e4;
  animation: eff70 2.2s linear infinite;
}
.span702{
  width: 39px;
  margin-left: 10px;
  animation: eff70 2.4s linear infinite;
}
@keyframes eff70{
  0%{
    opacity: 0.2;
  }
  50%{
    opacity: 1;
  }
  100%{
    opacity: 0.2;
  }
}

1、定义整体列表块通用样式,设置一个浅一点的背景色,设置 display: flex 布局。

2、利用 flex 布局,分别写出列表块中的每个小的矩形,并且设置相关的样式颜色等。

3、给列表块里的每个小的矩形设置 animation 动画,并且设置相关参数,每个动画时长递增 0.2s

4、设置动画关键帧,定义变化 opacity 透明属性,让列表块中的小的矩形由浅到深循环变化,这样就形成了视觉上列表块内容在加载的效果。

完整代码如下

html 页面

<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="style.css">
    <title>列表块加载动效</title>
  </head>
  <body>
    <div class="app">
      <div class="list-box70">
        <div class="pic70"></div>
        <div class="list70">
          <span class="span70"></span>
          <div class="span-div70">
            <span class="span701"></span>
            <span class="span702"></span>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>

css 样式

/** style.css **/
.app{
  width: 100%;
  height: 100vh;
  background-color: #ffffff;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}
.list-box70{
  width: 200px;
  height: 76px;
  position: relative;
  background-color: #f8f8f8;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  box-sizing: border-box;
}
.pic70{
  width: 44px;
  height: 44px;
  position: relative;
  background-color: #e4e4e4;
  border-radius: 4px;
  animation: eff70 1.8s linear infinite;
}
.list70{
  position: relative;
  display: flex;
  flex-direction: column;
  margin-left: 10px;
}
.span70{
  width: 114px;
  height: 20px;
  position: relative;
  border-radius: 4px;
  background-color: #e4e4e4;
  animation: eff70 2s linear infinite;
}
.span-div70{
  position: relative;
  margin-top: 10px;
  display: flex;
}
.span701,.span702{
  width: 65px;
  height: 14px;
  position: relative;
  border-radius: 4px;
  background-color: #e4e4e4;
  animation: eff70 2.2s linear infinite;
}
.span702{
  width: 39px;
  margin-left: 10px;
  animation: eff70 2.4s linear infinite;
}
@keyframes eff70{
  0%{
    opacity: 0.2;
  }
  50%{
    opacity: 1;
  }
  100%{
    opacity: 0.2;
  }
}

页面渲染效果

以上就是所有代码,以及简单的思路,希望对你有一些帮助或者启发。


[1] 原文阅读

[2] 《有趣的css》,访问网址:funcss.liujueyi.cn,欢迎大家访问。


我是 Just,这里是「设计师工作日常」,求点赞求关注!

  • 23
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

设计师工作日常

请我炫个饼🫓

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值