Here's a complete, self-contained HTML file that creates four animated weather cards (Wind, Rain, Sun, Snow), each with unique visual effects. The cards are displayed side-by-side, and a set of buttons allows the user to switch between the weather conditions to demonstrate the animations.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Animated Weather Cards</title>
<style>
body {
background-color: #000;
color: #fff;
font-family: 'Arial', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
padding: 20px;
}
.controls {
margin-bottom: 20px;
}
.controls button {
margin: 0 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background: #222;
color: #fff;
border: 1px solid #555;
border-radius: 5px;
transition: background 0.3s;
}
.controls button:hover {
background: #444;
}
.weather-container {
display: flex;
justify-content: space-around;
width: 100%;
max-width: 1200px;
}
.weather-card {
background-color: #111;
border: 2px solid #444;
border-radius: 10px;
padding: 20px;
width: 200px;
height: 200px;
position: relative;
overflow: hidden;
}
/* Keyframes for animations */
@keyframes wind {
0% { transform: translateX(0); }
100% { transform: translateX(-100%); }
}
@keyframes rain {
0% { transform: translateY(0); }
100% { transform: translateY(100vh); }
}
@keyframes sun {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@keyframes snow {
0% { transform: translateY(0); }
100% { transform: translateY(100vh); }
}
/* Animation classes */
.wind-animation .cloud {
animation: wind 10s linear infinite;
}
.rain-animation .raindrop {
animation: rain 2s linear infinite;
}
.sun-animation .sun-rays {
animation: sun 5s linear infinite;
}
.snow-animation .snowflake {
animation: snow 5s linear infinite;
}
/* Styling for elements inside cards */
.cloud {
width: 100px;
height: 50px;
background: white;
border-radius: 50%;
position: absolute;
top: 50px;
left: 0;
}
.raindrop {
width: 2px;
height: 10px;
background: white;
position: absolute;
opacity: 0.8;
}
.sun {
width: 50px;
height: 50px;
background: yellow;
border-radius: 50%;
position: absolute;
top: 50px;
left: 75px;
}
.sun-rays {
width: 100px;
height: 100px;
position: absolute;
top: 0;
left: 0;
transform-origin: center;
border: 2px solid yellow;
border-radius: 50%;
opacity: 0.6;
}
.snowflake {
width: 10px;
height: 10px;
background: white;
border-radius: 50%;
position: absolute;
opacity: 0.8;
}
</style>
</head>
<body>
<div class="controls">
<button onclick="showWeather('wind')">Wind</button>
<button onclick="showWeather('rain')">Rain</button>
<button onclick="showWeather('sun')">Sun</button>
<button onclick="showWeather('snow')">Snow</button>
</div>
<div class="weather-container">
<div id="wind-card" class="weather-card"></div>
<div id="rain-card" class="weather-card"></div>
<div id="sun-card" class="weather-card"></div>
<div id="snow-card" class="weather-card"></div>
</div>
<script>
function createWeatherElements() {
// Wind Card
const windCard = document.getElementById('wind-card');
const cloud = document.createElement('div');
cloud.className = 'cloud';
windCard.appendChild(cloud);
// Rain Card
const rainCard = document.getElementById('rain-card');
for (let i = 0; i < 50; i++) {
const raindrop = document.createElement('div');
raindrop.className = 'raindrop';
raindrop.style.left = Math.random() * 100 + '%';
raindrop.style.top = '-10px';
raindrop.style.opacity = Math.random();
raindrop.style.animationDuration = (Math.random() * 2 + 1) + 's';
rainCard.appendChild(raindrop);
}
// Sun Card
const sunCard = document.getElementById('sun-card');
const sun = document.createElement('div');
sun.className = 'sun';
sunCard.appendChild(sun);
const rays = document.createElement('div');
rays.className = 'sun-rays';
sunCard.appendChild(rays);
// Snow Card
const snowCard = document.getElementById('snow-card');
for (let i = 0; i < 100; i++) {
const snowflake = document.createElement('div');
snowflake.className = 'snowflake';
snowflake.style.left = Math.random() * 100 + '%';
snowflake.style.top = '-10px';
snowflake.style.opacity = Math.random();
snowflake.style.animationDuration = (Math.random() * 5 + 3) + 's';
snowCard.appendChild(snowflake);
}
}
function showWeather(weatherType) {
const cards = document.querySelectorAll('.weather-card');
cards.forEach(card => {
card.classList.remove('wind-animation', 'rain-animation', 'sun-animation', 'snow-animation');
});
const selectedCard = document.getElementById(`${weatherType}-card`);
selectedCard.classList.add(`${weatherType}-animation`);
}
window.onload = createWeatherElements;
</script>
</body>
</html>
✅ Features
- Dark Background: The entire page has a dark theme.
- Side-by-Side Cards: Four cards are displayed using
flexbox.
- Weather Animations:
- Wind: Moving cloud.
- Rain: Falling raindrops with randomized speed and position.
- Sun: Rotating rays around the sun.
- Snow: Falling snowflakes with randomized speed and position.
- Interactive Switching: Buttons allow the user to switch between weather conditions to see the animations.
You can copy and paste this code directly into an .html file and open it in your browser to see the animated weather cards in action.