效果预览

按下右侧的“点击预览”按钮可以在当前页面预览,点击链接可以全屏预览。

https://codepen.io/comehope/pen/oybWBy

可交互视频教程

此视频是可以交互的,你可以随时暂停视频,编辑视频中的代码。

请用 chrome, safari, edge 打开观看。

https://scrimba.com/p/pEgDAM/cG64puy

源代码下载

每日前端实战系列的全部源代码请从 github 下载:

https://github.com/comehope/front-end-daily-challenges

代码解读

定义 dom,容器中包含 5 个子元素:

<div class="equalizer">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>

居中显示:

body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: black;
}

定义均衡器的样式:

.equalizer {
width: 10em;
height: 10em;
display: flex;
justify-content: space-between;
} .equalizer span {
width: 1.5em;
background: linear-gradient(0deg, green, yellow, red);
}

定义均衡器竖条的动画效果:

.equalizer span {
animation: up-and-down 2s linear infinite;
} @keyframes up-and-down{
0%, 100% {
clip-path: inset(27% 0 0 0);
} 10% {
clip-path: inset(17% 0 0 0);
} 20% {
clip-path: inset(55% 0 0 0);
} 30% {
clip-path: inset(30% 0 0 0);
} 40% {
clip-path: inset(13% 0 0 0);
} 50% {
clip-path: inset(38% 0 0 0);
} 60% {
clip-path: inset(80% 0 0 0);
} 70% {
clip-path: inset(21% 0 0 0);
} 80% {
clip-path: inset(0% 0 0 0);
} 90% {
clip-path: inset(36% 0 0 0);
}
}

最后,设置各竖条依次动画:

.equalizer span {
animation: up-and-down 2s linear infinite calc(-1 * 0.4s * (var(--n) - 1));
} .equalizer span:nth-child(1) {
--n: 1;
} .equalizer span:nth-child(2) {
--n: 2;
} .equalizer span:nth-child(3) {
--n: 3;
} .equalizer span:nth-child(4) {
--n: 4;
} .equalizer span:nth-child(5) {
--n: 5;
}

大功告成!

最新文章

  1. 那些年黑了你的微软BUG
  2. #pragma pack(push,1)与#pragma pack(1)的区别
  3. emgucv文字识别
  4. 彻底理解ThreadLocal一
  5. 【leetcode】Distinct Subsequences(hard)
  6. meta 页面元信息定义
  7. spring + shiro + cas 实现sso单点登录
  8. 关于LeetCode的Largest Rectangle in Histogram的低级解法
  9. ECMAScript 6 中的快捷语法汇总及代码示例
  10. WebGL three.js学习笔记 使用粒子系统模拟时空隧道(虫洞)
  11. Linux IO模型(同步异步阻塞非阻塞等)的几篇好文章
  12. mysql的严格模式与无效字符编码问题
  13. c# 关于页面生命周期
  14. 6.JAVA基础复习——JAVA中文档注释与帮助文档的生成
  15. Django的认证系统和Django admin的简单使用
  16. redis安装linux(二)
  17. 常用JVM命令
  18. FineReport中如何安装移动端H5插件
  19. eclipse + maven + com.sun.jersey 创建 restful api
  20. mysql---总体备份和增量备份

热门文章

  1. C2. Power Transmission (Hard Edition)(线段相交)
  2. python编程练习题目
  3. kubectl格式化输出和调试
  4. form提供的两种数据传输方式 get和post method=”post“和method=”get”
  5. numpy模块介绍
  6. Windows下定时任务重启tomcat
  7. spring boot 测试插件使用及result风格实例1&amp;打包启动
  8. python语法基础-基础-运算符
  9. when|nobody|hazard|lane|circuit|
  10. Linux下文件 ~/.bashrc 和 ~/.bash_profile 和 /etc/bashrc 和 /etc/profile 的区别 | 用户登录后加载配置文件的顺序