梁鑫峰 發表於 2026-5-3 22:16:50

CSS实现音频播放时柱状波动效果

<p>通过CSS的动画属性animation可以实现音频播放时的动画效果,同时配合JS操作动画的animation-play-state属性,来控制动画的暂停和播放。</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202310/2023101017181181.png" /></p>
<p>网页布局采用的flex布局。若在客户端展示,可使用定位布局(本人遇到flex布局会出现底部轻微颤动的bug)</p>
<div class="jb51code"><pre class="brush:css;">.voice-playing{
    height: 50px;
    width: 40px;
    display: flex;
    /* 底部对齐,实现从下往上的动画效果 */
    align-items: flex-end;
    justify-content: space-between;
}
.play1{
    width: 10px;
    background-color: #bfc;
    animation: playing1 1s linear infinite alternate;
}
.play2{
    width: 10px;
    background-color: #bfc;
    animation: playing2 1s linear infinite alternate;
}
.play3{
    width: 10px;
    height: 10px;
    background-color: #bfc;
    animation: playing3 1s .5s linear infinite alternate;
}
@keyframes playing1 {
    0%{
      height: 10px;
    }
    100%{
      height: 30px;
    }
}
@keyframes playing2 {
    0%{
      height: 30px;
    }
    100%{
      height: 10px;
    }
}
@keyframes playing3 {
    0%{
      height: 10px;
    }
    100%{
      height: 30px;
    }
}</pre></div>
頁: [1]
查看完整版本: CSS实现音频播放时柱状波动效果