我们创建了一个很酷的网页底部水波动画效果,通过不同的透明度和动画延迟时间营造出动态的水波纹效果。
代码说明
- HTML结构:
- 使用
<section>
标签定义了一个全屏的容器,背景颜色为深蓝色。 - 在
<section>
内创建了四个带有不同类名的<div>
元素,每个<div>
代表一个水波层。
- 使用
- CSS样式:
- 设置全局样式,使页面居中显示,并设置了背景颜色。
- 定义了
section
的样式,使其占据整个视口并隐藏溢出内容。 - 定义了
.wave
类的基本样式,包括宽度、高度、位置和背景图像。 - 使用Base64编码嵌入了水波图案的PNG图像。
- 分别定义了四个不同的
.wave
子类(.wave1
,.wave2
,.wave3
,.wave4
),每个类设置了不同的动画效果、透明度、层级和延迟时间。 - 使用
@keyframes
规则定义了两个动画效果animate1
和animate2
,分别控制背景图像水平移动的方向。
- 动画效果:
animation: animate1 15s linear infinite;
:这行CSS代码将animate1
动画应用到带有.wave1
类的元素上,动画持续时间为15秒,线性播放,无限循环。animation: animate2 15s linear infinite;
:这行CSS代码将animate2
动画应用到带有.wave2
类的元素上,动画持续时间为15秒,线性播放,无限循环。- 类似的动画效果应用于其他水波层,通过调整动画时间和延迟实现层次感。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>网页底部水波纹特效</title> <style> * { margin: 0; padding: 0; } section { position: relative; width: 100%; height: 100vh; background: #3586ff; overflow: hidden; } section .wave { width: 100%; height: 100px; position: absolute; bottom: 0; left: 0; background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAACnCAMAAADHcrH0AAAAXVBMVEUAAABpVcH////////////////Px+y0qeD//v////+cjtbg2/P9/f/////+/v/Z0/DDueb////////39fz19Pvk3/Tx8Prs6fj////u6/j29fz49/zp5vbk4PT////SAwGYAAAAHnRSTlMABe/E6fkeD77MCzCl2rEnFuLSjX08b2L0Vz+bUEnJtcpWAAANw0lEQVR42uzBgQAAAACAoP2pF6kCAAAAA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jMu2lurRDJ5Xica26uPTJwACGMCbM9JpZTudSxkp8SsVFTLXuhtsU9LdBQhgAP/KMTTnJEnixJxC2roAAfyDvTqmAQCAgSDk33Ul/NpcwAQA8I+AAWATMAAUCBgANgEDQIGAAWATMAAUCBgANgEDQIGAAWATMAAUCBgANgEDQIGAAWATMAAUCBgANgEDQIGAAWATMAAUCBgANgEDQIGAAWATMAAUCBgANgEDQIGAAWATMAAUCBgANgEDQIGAAWATMAAUCBgArr06pgEAgIEg5N91JfzY5AIm2AQMAAUCBoBNwABQIGAA2AQMAAUCBoBNwABQIGAAeHAFxjfBlhY0lgAAAABJRU5ErkJggg=="); background-size: 1800px 100px; } section .wave.wave1 { animation: animate1 15s linear infinite; z-index: 1000; opacity: 1; animation-delay: 0s; bottom: 0; } section .wave.wave2 { animation: animate2 15s linear infinite; z-index: 999; opacity: 0.5; animation-delay: -3s; bottom: 20px; } section .wave.wave3 { animation: animate1 10s linear infinite; z-index: 998; opacity: 0.2; animation-delay: -7s; bottom: 30px; } section .wave.wave4 { animation: animate2 5s linear infinite; z-index: 997; opacity: 0.71; animation-delay: -5s; bottom: 25px; } @keyframes animate1 { 0% { background-position-x: 0; } 100% { background-position-x: 1800px; } } @keyframes animate2 { 0% { background-position-x: 0; } 100% { background-position-x: -1800px; } } </style> </head> <body> <section> <div class="wave wave1 "></div> <div class="wave wave2 "></div> <div class="wave wave3 "></div> <div class="wave wave4"></div> </section> </body> </html>
No responses yet