Appearance
涟漪背景
多个同心圆从中心点向外扩散,形成平静柔和的背景涟漪效果。
实时预览
代码
html
<div class="ripple-bg">
<div class="ripple-ring"></div>
<div class="ripple-ring"></div>
<div class="ripple-ring"></div>
<!-- 4-6 个圆环,设置错开的动画延迟 -->
</div>
<style>
.ripple-bg {
background: #0a0a1a;
position: relative;
overflow: hidden;
}
.ripple-ring {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
border: 2px solid rgba(102,126,234,.4);
border-radius: 50%;
animation: ripple-expand 4s ease-out infinite;
}
.ripple-ring:nth-child(1) { animation-delay: 0s; }
.ripple-ring:nth-child(2) { animation-delay: 0.8s; }
.ripple-ring:nth-child(3) { animation-delay: 1.6s; }
.ripple-ring:nth-child(4) { animation-delay: 2.4s; }
@keyframes ripple-expand {
0% {
width: 0; height: 0;
opacity: 0.8;
border-width: 2px;
}
100% {
width: 500px; height: 500px;
opacity: 0;
border-width: 1px;
}
}
</style>纯 CSS 实现的涟漪背景背景动画——通过渐变、滤镜和 @keyframes 创建动态背景效果。无需 Canvas、WebGL 或任何 JavaScript,即可让页面背景"活"起来。
快速使用
- 复制 CSS 代码(含
@keyframes)到你的样式文件中 - 将背景动画样式应用到目标容器元素上
- 调整
background-size和animation-duration控制效果 - 确保容器有明确的高度(
min-height),否则背景可能不可见
使用场景
- 品牌落地页:用渐变流动或极光背景提升页面的高级感
- 技术/黑客主题页面:矩阵代码雨或粒子背景传递科技氛围
- 创意/设计类网站:浮动光斑或网格动画展现设计感
- 节日/活动页面:动态背景配合主题色营造节日氛围
常见问题
Q: 背景动画会消耗很多 CPU 吗? A: 会消耗一定的 GPU 资源。建议在用户不可见时(如切换标签页)暂停动画,用 animation-play-state: paused 配合 document.hidden API。移动端慎用多个滤镜叠加。
Q: 如何让背景动画不影响内容可读性? A: 在动画层之上加一个半透明遮罩层(如 background: rgba(0,0,0,0.4)),或将文字放在独立的叠层中。也可以降低动画的 opacity 到 0.3~0.5。
Q: 背景动画在所有浏览器下都正常吗? A: conic-gradient 需要较新浏览器版本。@property 仅 Chrome/Edge。建议提供降级方案:用 linear-gradient + background-position 动画替代。
浏览器兼容性
| 浏览器 | 兼容性 |
|---|---|
| Chrome / Edge | ✅ 完全支持(含 conic-gradient、@property) |
| Firefox | ✅ 基本支持(不含 @property) |
| Safari | ✅ 基本支持 |
| 移动端浏览器 | ✅ 完全支持 |
| IE 11 | ❌ 高级渐变和动画不支持 |