html
<template>
<view
class="wave-container"
>
<view :class="`wave-bar wave-bar-delay-${n}`" v-for="n in generateSequence(20)" :key="n"></view>
</view>
</template>
<script lang="ts" setup>
function generateSequence(n) {
const result = []
// 递增部分:1 到 n
for (let i = 1; i <= n; i++) {
result.push(i)
}
// 递减部分:n-1 到 1
for (let i = n - 1; i >= 1; i--) {
result.push(i)
}
return result
}
</script>
<style lang="scss" scoped>
$number: 20;
.wave-container {
display: flex;
gap: 5px;
align-items: center;
justify-content: center;
width: 100%;
height: 22px;
padding: 12px 0;
border-radius: 10px;
background-color: aqua;
}
.wave-bar {
width: 3px;
height: 10px;
background-color: #fff;
border-radius: 2px;
animation: wave 1s infinite ease-in-out;
}
@for $i from 1 through $number {
.wave-bar-delay-#{$i} {
animation-delay: $i * -0.8 + s;
}
}
@keyframes wave {
0%,
100% {
transform: scaleY(0.8);
}
50% {
transform: scaleY(1);
}
}
</style>
效果,这里我设置的高度
和scaleY
变化比较小
