I'll help create an animated weather card system with different weather conditions. Here's a complete solution with HTML, CSS, and JavaScript in a single file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Animated Weather Cards</title>
<style>
body {
margin: 0;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #1a1a1a;
font-family: Arial, sans-serif;
padding: 20px;
flex-wrap: wrap;
gap: 20px;
}
.weather-card {
width: 200px;
height: 300px;
background: #2a2a2a;
border-radius: 15px;
position: relative;
overflow: hidden;
box-shadow: 0 0 20px rgba(0,0,0,0.3);
}
/* Sun Animation */
.sun-card .sun {
width: 60px;
height: 60px;
background: #FFD700;
border-radius: 50%;
position: absolute;
top: 40px;
left: 70px;
animation: glow 3s infinite;
}
.sun-ray {
position: absolute;
background: #FFD700;
width: 4px;
height: 20px;
border-radius: 2px;
}
@keyframes glow {
0%, 100% { transform: scale(1); box-shadow: 0 0 20px #FFD700; }
50% { transform: scale(1.1); box-shadow: 0 0 40px #FFD700; }
}
/* Rain Animation */
.raindrop {
position: absolute;
width: 2px;
height: 20px;
background: #4FC3F7;
border-radius: 50%;
}
@keyframes rain {
0% { transform: translateY(-20px); opacity: 0; }
50% { opacity: 1; }
100% { transform: translateY(300px); opacity: 0; }
}
/* Snow Animation */
.snowflake {
position: absolute;
width: 6px;
height: 6px;
background: white;
border-radius: 50%;
}
@keyframes snow {
0% { transform: translateY(-20px) rotate(0deg); opacity: 0; }
50% { opacity: 1; }
100% { transform: translateY(300px) rotate(360deg); opacity: 0; }
}
/* Wind Animation */
.wind-line {
position: absolute;
height: 2px;
background: rgba(255,255,255,0.3);
border-radius: 1px;
}
@keyframes wind {
0% { transform: translateX(-100%) scaleX(1); opacity: 0; }
50% { opacity: 1; }
100% { transform: translateX(200%) scaleX(1.5); opacity: 0; }
}
.weather-title {
position: absolute;
bottom: 20px;
width: 100%;
text-align: center;
color: white;
font-size: 1.2em;
}
</style>
</head>
<body>
<div class="weather-card sun-card">
<div class="sun"></div>
<div class="weather-title">Sunny</div>
</div>
<div class="weather-card rain-card">
<div class="weather-title">Rainy</div>
</div>
<div class="weather-card snow-card">
<div class="weather-title">Snowy</div>
</div>
<div class="weather-card wind-card">
<div class="weather-title">Windy</div>
</div>
<script>
// Sun rays creation
const sunCard = document.querySelector('.sun-card');
for(let i = 0; i < 8; i++) {
const ray = document.createElement('div');
ray.className = 'sun-ray';
ray.style.transform = `rotate(${i * 45}deg)`;
ray.style.left = '98px';
ray.style.top = '60px';
sunCard.appendChild(ray);
}
// Rain animation
const rainCard = document.querySelector('.rain-card');
function createRain() {
const raindrop = document.createElement('div');
raindrop.className = 'raindrop';
raindrop.style.left = Math.random() * 180 + 10 + 'px';
raindrop.style.animation = `rain ${Math.random() * 0.5 + 0.5}s linear infinite`;
rainCard.appendChild(raindrop);
setTimeout(() => raindrop.remove(), 2000);
}
setInterval(createRain, 50);
// Snow animation
const snowCard = document.querySelector('.snow-card');
function createSnow() {
const snowflake = document.createElement('div');
snowflake.className = 'snowflake';
snowflake.style.left = Math.random() * 180 + 10 + 'px';
snowflake.style.animation = `snow ${Math.random() * 2 + 2}s linear infinite`;
snowCard.appendChild(snowflake);
setTimeout(() => snowflake.remove(), 4000);
}
setInterval(createSnow, 200);
// Wind animation
const windCard = document.querySelector('.wind-card');
function createWind() {
const windLine = document.createElement('div');
windLine.className = 'wind-line';
windLine.style.top = Math.random() * 260 + 20 + 'px';
windLine.style.width = Math.random() * 50 + 30 + 'px';
windLine.style.animation = `wind ${Math.random() * 0.5 + 0.5}s linear`;
windCard.appendChild(windLine);
setTimeout(() => windLine.remove(), 2000);
}
setInterval(createWind, 200);
</script>
</body>
</html>
This code creates four weather cards displayed side by side, each showing a different weather condition with unique animations:
- Sunny: Features a glowing sun with animated rays
- Rainy: Shows continuously falling raindrops
- Snowy: Displays gently falling and rotating snowflakes
- Windy: Demonstrates wind movement with animated lines
Key features:
- Responsive design that works on different screen sizes
- Dark theme with contrasting weather elements
- Smooth animations using CSS keyframes
- Dynamic element creation using JavaScript
- Automatic cleanup of animation elements to prevent memory issues
- Each weather condition has its own unique visual style and animation pattern
The animations run continuously and are created using a combination of CSS animations and JavaScript for element generation and management. The cards have a dark background with good contrast for the weather elements.
To use this, simply save it as an HTML file and open it in a web browser. All weather conditions will be displayed simultaneously, making it easy to compare the different animations.