有趣的css - 图片懒加载小动效

大家好,我是 Just,这里是「设计师工作日常」,今天分享的是用 css 实现图片内容懒加载小动效,适用于图片列表懒加载等场景。

《有趣的css》系列最新实例通过公众号「设计师工作日常」发布。


整体效果

知识点:
① css 绘制三角形、
animation 动画属性。

使用 css 绘制出图片图标,通过 animation 动画分别让图标的各部分动起来。

用 css 实现图片内容懒加载小动效,适用于图片列表懒加载等场景。


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

核心代码

html 代码

<div class="loading39">
  <span class="round39"></span>
  <span class="one-sj39"></span>
  <span class="two-sj39"></span>
</div>

3 个 span 标签分别作为图片图标的 3 个主体部分( 1 个圆、2 个三角形)。

css 部分代码

.loading39{
  width: 88px;
  height: 88px;
  background-color: #ffffff;
  position: relative;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  overflow: hidden; /*限制益处*/
}
/*圆形*/
.round39{
  width: 18px;
  height: 18px;
  border-radius: 9px;
  background-color: #d6d6d6;
  position: absolute;
  animation: round39-eff 3s both infinite;
}
/*第一个三角形*/
.one-sj39{
  border-bottom: 30px solid #ddd;
  border-left: 24px solid transparent;
  border-right: 24px solid transparent;
  position: absolute;
  animation: one-sj39-eff 3s both infinite;
}
/*第二个三角形*/
.two-sj39{
  border-bottom: 44px solid #d1d1d1;
  border-left: 30px solid transparent;
  border-right: 30px solid transparent;
  position: absolute;
  right: 0;
  animation: two-sj39-eff 3s both infinite;
}
@keyframes round39-eff{
  0%{
    top: 16px;
    left: 88px;
  }
  50%{
    top: 14px;
    left: 24px;
  }
  100%{
    top: 16px;
    left: -18px;
  }
}
@keyframes one-sj39-eff{
  0%{
    bottom: -30px;
  }
  50%{
    bottom: 0;
  }
  100%{
    bottom: -30px;
  }
}
@keyframes two-sj39-eff{
  0%{
    bottom: -44px;
  }
  50%{
    bottom: 0;
  }
  100%{
    bottom: -44px;
  }
}

1、分别绘制一个圆形,以及两个三角形,这里三角形是通过 border 方法来实现的,实现代码可看 css 部分注释说明。

2、绘制好整体图标形状后,再给 3 个主体分别加上 animation 动画属性,然后设置不同的参数:
如圆形我们设置为从右至左出现,然后消失;
三角形部分则从下往上出现,然后再往下消失。

完整代码如下

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="loading39">
        <span class="round39"></span>
        <span class="one-sj39"></span>
        <span class="two-sj39"></span>
      </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;
}
.loading39{
  width: 88px;
  height: 88px;
  background-color: #ffffff;
  position: relative;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  overflow: hidden;
}
.round39{
  width: 18px;
  height: 18px;
  border-radius: 9px;
  background-color: #d6d6d6;
  position: absolute;
  animation: round39-eff 3s both infinite;
}
.one-sj39{
  border-bottom: 30px solid #ddd;
  border-left: 24px solid transparent;
  border-right: 24px solid transparent;
  position: absolute;
  animation: one-sj39-eff 3s both infinite;
}
.two-sj39{
  border-bottom: 44px solid #d1d1d1;
  border-left: 30px solid transparent;
  border-right: 30px solid transparent;
  position: absolute;
  right: 0;
  animation: two-sj39-eff 3s both infinite;
}
@keyframes round39-eff{
  0%{
    top: 16px;
    left: 88px;
  }
  50%{
    top: 14px;
    left: 24px;
  }
  100%{
    top: 16px;
    left: -18px;
  }
}
@keyframes one-sj39-eff{
  0%{
    bottom: -30px;
  }
  50%{
    bottom: 0;
  }
  100%{
    bottom: -30px;
  }
}
@keyframes two-sj39-eff{
  0%{
    bottom: -44px;
  }
  50%{
    bottom: 0;
  }
  100%{
    bottom: -44px;
  }
}

页面渲染效果

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


[1] 原文阅读


CSS 是一种很酷很有趣的计算机语言,在这里跟大家分享一些 CSS 实例 Demo,为学习者获取灵感和思路提供一点帮助,希望你们喜欢。

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

设计师工作日常

请我炫个饼🫓

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

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

打赏作者

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

抵扣说明:

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

余额充值