有趣的 CSS - 动态圆点水波纹效果

先看效果

整体效果

这个效果使用 css 中 animation 属性,以及搭配伪元素 ::after::before 来实现两个圆交替变化。

核心代码

html部分代码

<div>
  <label class="dot"></label>
</div>

label 标签画圆点主体。

css部分代码

.app{
   
  width: 100%;
  height: 100vh;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}
.dot {
   
  width: 48px;
  height: 48px;
  display: block;
  position: relative;
  border-radius: 50%;
  background-color: blue;
  z-index: 1;
}
.dot::after {
   
  width: 100%;
  height: 100%;
  content: "";
  border-radius: 50%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -2;
  background-color: blue;
  animation: dot-play 4s linear 400ms infinite;
}
.dot::before {
   
  width: 100%;
  height: 100%;
  content: "";
  border-radius: 50%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  background-color: blue;
  animation: dot-play 4s linear 200ms infinite;
  animation-delay: 2s; /* 延迟 2s */
}
@keyframes dot-play{
   
  from{
   
    transform: scale(1);
    opacity: .2;
  }
  to{
   
    transform: scale(4);
    opacity: 0;
  }
}

伪元素基于主体圆写出两个蓝色圆形来做水波纹,并设置 animation 属性进行变化。
注意:第二个伪元素的圆形,延迟 2s 启动 animation 动画。

完整代码

html代码

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="style.css?k3f22ww">
  <title>03 圆点水波纹效果</title>
</head>
<body>
  <div class="app">
    <label class="dot"></label>
  </div>
</body>
</html>

css代码

*{
   
  margin: 0;
  padding: 0;
  list-style: none;
  transition: .5s;
}
html,body{
   
  background-color: #f5f5f5;
  color: #fff;
  font-size: 14px;
}
.app{
   
  width: 100%;
  height: 100vh;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}
.dot {
   
  width: 48px;
  height: 48px;
  display: block;
  position: relative;
  border-radius: 50%;
  background-color: blue;
  z-index: 1;
}
.dot::after {
   
  width: 100%;
  height: 100%;
  content: "";
  border-radius: 50%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -2;
  background-color: blue;
  animation: dot-play 4s linear 400ms infinite;
}
.dot::before {
   
  width: 100%;
  height: 100%;
  content: "";
  border-radius: 50%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  background-color: blue;
  animation: dot-play 4s linear 200ms infinite;
  animation-delay: 2s; /* 延迟 2s */
}
@keyframes dot-play{
   
  from{
   
    transform: scale(1);
    opacity: .2;
  }
  to{
   
    transform: scale(4);
    opacity: 0;
  }
}

页面效果


[1] 阅读原文

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

相关推荐

  1. 使用css3实现【波纹扩散效果

    2024-01-29 22:36:01       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-29 22:36:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-29 22:36:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-29 22:36:01       82 阅读
  4. Python语言-面向对象

    2024-01-29 22:36:01       91 阅读

热门阅读

  1. 蓝桥杯真题刷题1.倍数

    2024-01-29 22:36:01       50 阅读
  2. 【sql学习-深入学习和应用】

    2024-01-29 22:36:01       52 阅读
  3. 海思 tcpdump 移植开发详解

    2024-01-29 22:36:01       53 阅读
  4. Qt/QML编程之路:qml通过C++传递变量给另一个qml(42)

    2024-01-29 22:36:01       58 阅读
  5. 51单片机——感应开关盖垃圾桶

    2024-01-29 22:36:01       43 阅读
  6. 面试 HTML 框架八股文十问十答第二期

    2024-01-29 22:36:01       61 阅读
  7. LeetCode 第十八天

    2024-01-29 22:36:01       66 阅读
  8. Linux编程 1/2 数据结构

    2024-01-29 22:36:01       57 阅读