1句话生成了一个教学动画:通过HTML/CSS动画展示冷暖空气对流导致下雨的全过程
写一个冷暖对流导致下大雨的html代码,动态显示对流竞争的过程
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>冷暖空气对流导致下雨</title>
<style>
body {
margin: 0;
overflow: hidden;
background: linear-gradient(to bottom, #87CEEB, #1E90FF);
font-family: Arial, sans-serif;
}
#container {
position: relative;
width: 800px;
height: 500px;
margin: 20px auto;
border: 2px solid #333;
background: linear-gradient(to bottom, #E0F7FA, #B2EBF2);
overflow: hidden;
}
.ground {
position: absolute;
bottom: 0;
width: 100%;
height: 100px;
background: linear-gradient(to bottom, #8BC34A, #4CAF50);
}
.warm-air {
position: absolute;
width: 200px;
height: 100px;
background: rgba(255, 165, 0, 0.5);
border-radius: 50% 50% 0 0;
bottom: 100px;
left: 300px;
animation: rise 8s infinite;
}
.cold-air {
position: absolute;
width: 200px;
height: 100px;
background: rgba(0, 191, 255, 0.5);
border-radius: 0 0 50% 50%;
top: 0;
left: 300px;
animation: fall 8s infinite;
}
.cloud {
position: absolute;
width: 200px;
height: 80px;
background: rgba(255, 255, 255, 0.8);
border-radius: 50%;
top: 50px;
left: 300px;
opacity: 0;
animation: form-cloud 8s infinite;
}
.rain {
position: absolute;
width: 2px;
height: 20px;
background: rgba(0, 191, 255, 0.7);
top: 130px;
left: 400px;
opacity: 0;
animation: rain 8s infinite;
}
.explanation {
position: absolute;
bottom: 10px;
left: 10px;
background: rgba(255, 255, 255, 0.7);
padding: 10px;
border-radius: 5px;
max-width: 300px;
}
@keyframes rise {
0% { transform: translateY(0); opacity: 0.5; }
25% { transform: translateY(-100px); opacity: 0.7; }
50% { transform: translateY(-200px); opacity: 0.3; }
75% { transform: translateY(-300px); opacity: 0; }
100% { transform: translateY(-300px); opacity: 0; }
}
@keyframes fall {
0% { transform: translateY(0); opacity: 0.5; }
25% { transform: translateY(100px); opacity: 0.7; }
50% { transform: translateY(200px); opacity: 0.3; }
75% { transform: translateY(300px); opacity: 0; }
100% { transform: translateY(300px); opacity: 0; }
}
@keyframes form-cloud {
0% { opacity: 0; transform: scale(0.5); }
50% { opacity: 0; transform: scale(0.5); }
60% { opacity: 0.8; transform: scale(1); }
90% { opacity: 0.8; transform: scale(1); }
100% { opacity: 0; transform: scale(1.2); }
}
@keyframes rain {
0% { opacity: 0; }
60% { opacity: 0; }
65% { opacity: 1; transform: translateY(0); }
100% { opacity: 1; transform: translateY(200px); }
}
.title {
text-align: center;
color: #333;
margin-top: 20px;
}
.controls {
text-align: center;
margin: 10px;
}
button {
padding: 8px 15px;
background: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<h1 class="title">冷暖空气对流导致下雨的过程</h1>
<div class="controls">
<button onclick="restartAnimation()">重新播放</button>
</div>
<div id="container">
<div class="ground"></div>
<div class="warm-air"></div>
<div class="cold-air"></div>
<div class="cloud"></div>
<div class="rain"></div>
<div class="explanation">
<h3>对流降雨过程:</h3>
<ol>
<li>地面暖湿空气受热上升</li>
<li>高空冷空气下沉</li>
<li>冷暖空气相遇形成对流</li>
<li>水汽凝结形成云</li>
<li>云中水滴增大形成降雨</li>
</ol>
</div>
</div>
<script>
function createMultipleRainDrops() {
const container = document.getElementById('container');
// 清除现有的雨滴
const existingRain = document.querySelectorAll('.rain-drop');
existingRain.forEach(drop => drop.remove());
// 创建多个雨滴
for (let i = 0; i < 50; i++) {
const rain = document.createElement('div');
rain.className = 'rain rain_drop';
// 随机位置
const left = Math.random() * 700 + 50;
const delay = Math.random() * 4;
// 设置样式
rain.style.left = left + 'px';
rain.style.animationDelay = delay + 's';
container.appendChild(rain);
}
}
function restartAnimation() {
// 重新创建雨滴
createMultipleRainDrops();
// 重新触发动画
const elements = document.querySelectorAll('.warm-air, .cold-air, .cloud, .rain');
elements.forEach(el => {
el.style.animation = 'none';
void el.offsetWidth; // 触发重绘
el.style.animation = '';
});
}
// 初始创建雨滴
window.onload = createMultipleRainDrops;
</script>
</body>
</html>