Sure! Here's a complete single HTML file that includes CSS , JavaScript , and HTML to display animated weather cards for:
Each card is shown side by side with buttons to switch the animation of each card. The background is dark, and each weather has a distinct animation as requested.
✅ Features Included:
Dark theme
Animated for each weather type:
Wind – moving clouds
Rain – falling raindrops
Sun – glowing sun rays
Snow – falling snowflakes
Buttons to switch weather condition for demonstration
Fully responsive design
📄 Complete HTML Below:
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Animated Weather Cards</title>
<style>
body {
margin: 0;
background: #121212;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: white;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
h1 {
margin-bottom: 20px;
}
.cards-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
justify-content: center;
}
.weather-card {
background: #1e1e1e;
width: 200px;
height: 250px;
border-radius: 10px;
position: relative;
overflow: hidden;
box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
text-align: center;
}
.card-title {
position: absolute;
top: 10px;
width: 100%;
text-align: center;
font-weight: bold;
}
/* Wind Animation */
.wind .cloud {
position: absolute;
width: 60px;
height: 30px;
background: #ccc;
border-radius: 50%;
top: 50px;
left: -70px;
animation: windMove 5s linear infinite;
}
@keyframes windMove {
0% { left: -70px; }
100% { left: 250px; }
}
/* Rain Animation */
.rain .raindrop {
position: absolute;
width: 2px;
height: 15px;
background: #00bfff;
top: -20px;
animation: rainFall 1s linear infinite;
}
@keyframes rainFall {
0% { transform: translateY(0); opacity: 1; }
100% { transform: translateY(250px); opacity: 0; }
}
/* Sun Animation */
.sun .sun-core {
width: 60px;
height: 60px;
background: yellow;
border-radius: 50%;
position: absolute;
box-shadow: 0 0 20px 5px yellow;
animation: sunPulse 2s ease-in-out infinite;
}
@keyframes sunPulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.1); }
}
/* Snow Animation */
.snow .snowflake {
position: absolute;
width: 8px;
height: 8px;
background: #fff;
border-radius: 50%;
opacity: 0.8;
top: -10px;
animation: snowFall 6s linear infinite;
}
@keyframes snowFall {
0% { transform: translateY(0); opacity: 1; }
100% { transform: translateY(250px); opacity: 0; }
}
.buttons {
margin-top: 20px;
}
.buttons button {
margin: 5px;
padding: 10px 20px;
background: #333;
color: #fff;
border: none;
cursor: pointer;
border-radius: 5px;
transition: background 0.3s;
}
.buttons button:hover {
background: #555;
}
</style>
</head>
<body>
<h1>Animated Weather Cards</h1>
<div class="cards-container" id="cardsContainer">
<div class="weather-card wind" data-type="wind">
<div class="card-title">Wind</div>
</div>
<div class="weather-card rain" data-type="rain">
<div class="card-title">Rain</div>
</div>
<div class="weather-card sun" data-type="sun">
<div class="card-title">Sun</div>
</div>
<div class="weather-card snow" data-type="snow">
<div class="card-title">Snow</div>
</div>
</div>
<div class="buttons">
<button onclick="setWeather('wind')">Wind</button>
<button onclick="setWeather('rain')">Rain</button>
<button onclick="setWeather('sun')">Sun</button>
<button onclick="setWeather('snow')">Snow</button>
<button onclick="resetAll()">Reset</button>
</div>
<script>
function createCloud(card) {
const cloud = document.createElement("div");
cloud.className = "cloud";
card.appendChild(cloud);
}
function createRaindrops(card) {
for (let i = 0; i < 30; i++) {
const drop = document.createElement("div");
drop.className = "raindrop";
drop.style.left = Math.random() * 200 + 'px';
drop.style.animationDuration = (0.5 + Math.random()).toFixed(2) + 's';
card.appendChild(drop);
}
}
function createSun(card) {
const sun = document.createElement("div");
sun.className = "sun-core";
card.appendChild(sun);
}
function createSnowflakes(card) {
for (let i = 0; i < 20; i++) {
const flake = document.createElement("div");
flake.className = "snowflake";
flake.style.left = Math.random() * 200 + 'px';
flake.style.animationDuration = (3 + Math.random() * 3).toFixed(2) + 's';
card.appendChild(flake);
}
}
// Initialize all cards
window.onload = function () {
document.querySelectorAll(".weather-card").forEach(card => {
let type = card.dataset.type;
applyWeather(card, type);
});
};
function applyWeather(card, type) {
card.innerHTML = '<div class="card-title">' + type.charAt(0).toUpperCase() + type.slice(1) + '</div>';
if(type === "wind") {
createCloud(card);
} else if(type === "rain") {
createRaindrops(card);
} else if(type === "sun") {
createSun(card);
} else if(type === "snow") {
createSnowflakes(card);
}
}
function setWeather(type) {
document.querySelectorAll(".weather-card").forEach(card => {
card.className = "weather-card " + type;
card.dataset.type = type;
applyWeather(card, type);
});
}
function resetAll() {
const types = ["wind", "rain", "sun", "snow"];
const cards = document.querySelectorAll(".weather-card");
cards.forEach((card, index) => {
const type = types[index % types.length];
card.className = "weather-card " + type;
card.dataset.type = type;
applyWeather(card, type);
});
}
</script>
</body>
</html>
💡 How It Works:
CSS handles the visual styles and key animations.
JavaScript dynamically injects animation elements (like clouds, raindrops, sun, snowflakes).
Buttons call setWeather("type") to change animations for all cards.
resetAll() brings back one of each weather side by side.
Let me know if you would like responsive versions, toggles per card, or more effects like thunderstorms or fog! ☁️🌩️🌫️✨