css制作冒泡
使用 CSS 制作冒泡效果
关键属性
animation:控制动画的持续时间、延迟和循环方式。@keyframes:定义动画的具体变化过程。border-radius:实现圆形或椭圆形气泡形状。box-shadow:增强气泡的立体感。
基础实现代码
.bubble {
width: 30px;
height: 30px;
background-color: rgba(255, 255, 255, 0.6);
border-radius: 50%;
position: absolute;
bottom: 0;
animation: rise 4s infinite ease-in;
}
@keyframes rise {
0% {
transform: translateY(0) scale(0.8);
opacity: 0.5;
}
100% {
transform: translateY(-100vh) scale(1.2);
opacity: 0;
}
}
进阶优化
为气泡添加随机性和自然感:

.bubble:nth-child(1) {
left: 10%;
animation-delay: 0.5s;
}
.bubble:nth-child(2) {
left: 40%;
animation-delay: 1.2s;
animation-duration: 5s;
}
.bubble:nth-child(3) {
left: 70%;
animation-delay: 0.8s;
animation-duration: 3s;
}
动态效果增强
通过伪元素创建气泡高光:
.bubble::before {
content: '';
position: absolute;
top: 15%;
left: 20%;
width: 15%;
height: 15%;
background-color: white;
border-radius: 50%;
opacity: 0.7;
}
应用示例
将气泡容器设置为固定定位:
<div class="bubble-container">
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
</div>
<style>
.bubble-container {
position: fixed;
width: 100%;
height: 100%;
pointer-events: none;
z-index: -1;
}
</style>







