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

通过CSS的动画属性animation可以实现音频播放时的动画效果,同时配合JS操作动画的animation-play-state属性,来控制动画的暂停和播放。
CSS动画

网页布局采用的flex布局。若在客户端展示,可使用定位布局(本人遇到flex布局会出现底部轻微颤动的bug)

.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;
    }
}

猜你喜欢

转载自blog.csdn.net/yan_danfeng/article/details/127748872
今日推荐