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>

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

相关推荐
一斤代码2 小时前
vue3 下载图片(标签内容可转图)
前端·javascript·vue
中微子2 小时前
React Router 源码深度剖析解决面试中的深层次问题
前端·react.js
光影少年2 小时前
从前端转go开发的学习路线
前端·学习·golang
中微子3 小时前
React Router 面试指南:从基础到实战
前端·react.js·前端框架
3Katrina3 小时前
深入理解 useLayoutEffect:解决 UI "闪烁"问题的利器
前端·javascript·面试
前端_学习之路4 小时前
React--Fiber 架构
前端·react.js·架构
伍哥的传说4 小时前
React 实现五子棋人机对战小游戏
前端·javascript·react.js·前端框架·node.js·ecmascript·js
qq_424409194 小时前
uniapp的app项目,某个页面长时间无操作,返回首页
前端·vue.js·uni-app
我在北京coding4 小时前
element el-table渲染二维对象数组
前端·javascript·vue.js
布兰妮甜4 小时前
Vue+ElementUI聊天室开发指南
前端·javascript·vue.js·elementui