vue3 css模拟语音通话不同语音、正在加载等的效果

实现效果如下:


在不同的时间,显示不一样的效果(大小是一样的,截图时尺寸发生了变化)

具体实现代码如下:

js 复制代码
<script setup>
import {ref} from "vue";

const max_hight = ref('40px')
const min_hight = ref('2px')
</script>

<template>
  <div class="loading loading-2">
    <ul>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
    </ul>
  </div>
</template>

<style scoped>
* {
  padding: 0;
  margin: 0;
  list-style: none;
}

.loading {
  width: 300px;
  height: v-bind(max_hight);
  margin: 100px auto;
}

.loading ul {
  height: v-bind(max_hight);
  width: 65px;
  margin: 0 auto;
  display: flex;
  align-items: center;
}

.loading ul li {
  margin: 0 2px;
  width: 3px;
  height: v-bind(max_hight);
  background-color: darkgrey;
}

/* 1) 定义动画 */
@keyframes ani-height {
  0% {
    height: v-bind(max_hight);
  }

  50% {
    height: v-bind(min_hight);
  }

  100% {
    height: v-bind(max_hight);
  }
}

/* 2) 使用动画 */
li:nth-child(1) {
  animation: ani-height .5s .1s linear infinite;
}

li:nth-child(2) {
  animation: ani-height .5s .05s linear infinite;
}

li:nth-child(3) {
  animation: ani-height .5s .2s linear infinite;
}

li:nth-child(4) {
  animation: ani-height .5s .25s linear infinite;
}

li:nth-child(5) {
  animation: ani-height .5s .15s linear infinite;
}
</style>

其实主要的差别就是在不同时刻,将其高度设置成不一样的大小即可,也就是对动画的时间进行逐步后移即可

相关推荐
不会写DN16 小时前
如何通过 Python 实现招聘平台自动投递
开发语言·前端·python
miaowmiaow16 小时前
一行命令把 PSD 还原成 HTML / React / Vue:psd2code 实战干货
前端·ai编程
张元清16 小时前
React 中的语音与摄像头输入:语音识别、媒体设备与权限
前端·javascript·面试
用户8417948145616 小时前
vxe-table 实现撤销与重做:单元格编辑后支持 Ctrl+Z 回退
前端
石小石Orz17 小时前
OpenAI官方:harness-engineering(工程技术:在智能体优先的世界中利用 Codex)
前端·后端
Moment17 小时前
2026年,为什么NestJS + Monorepo越来越流行了 ❓❓❓
前端·后端·面试
前端那点事17 小时前
Vite4.x+打包优化实战指南(无冗余):从体积到速度,一文吃透所有技巧
前端·vue.js
Struggle_zy17 小时前
Vue3 动态路由踩坑记
前端
SurgeJS17 小时前
Vue Rex: 一个更简单的 Vue 3 请求库
前端
前端那点事17 小时前
Vue十万条数据渲染无卡顿!3种工业级方案(附可复制代码+避坑指南)
前端·vue.js