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 {
font-family: sans-serif;
background-color: #121212;
color: white;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
padding: 20px;
box-sizing: border-box;
}
.weather-container {
display: flex;
gap: 20px;
justify-content: center;
flex-wrap: wrap;
}
.weather-card {
background-color: #1e1e1e;
border-radius: 15px;
padding: 20px;
width: 300px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
position: relative;
overflow: hidden;
}
.weather-card h2 {
margin-top: 0;
margin-bottom: 10px;
text-align: center;
}
.weather-info {
margin-bottom: 15px;
}
.weather-info p {
margin: 5px 0;
}
.animation-container {
position: relative;
height: 150px; /* Adjust as needed for animation space */
overflow: hidden;
margin-bottom: 15px;
}
/* Common Animation Styles */
.cloud {
position: absolute;
background-color: rgba(255, 255, 255, 0.5);
border-radius: 50%;
width: 60px;
height: 30px;
top: 20px;
}
.cloud::after {
content: '';
position: absolute;
background-color: rgba(255, 255, 255, 0.5);
border-radius: 50%;
width: 40px;
height: 20px;
top: -10px;
left: 15px;
}
@keyframes wind-animation {
0% { transform: translateX(-100px); }
100% { transform: translateX(calc(100% + 100px)); }
}
.tree {
position: absolute;
bottom: 0;
width: 30px;
height: 50px;
background-color: #4CAF50;
border-radius: 2px 2px 10px 10px;
transform-origin: bottom center;
}
.tree::before {
content: '';
position: absolute;
top: -15px;
left: 5px;
width: 20px;
height: 20px;
background-color: #4CAF50;
border-radius: 50%;
}
@keyframes sway-tree {
0%, 100% { transform: rotate(0deg); }
50% { transform: rotate(5deg); }
}
.wind-line {
position: absolute;
background-color: rgba(255, 255, 255, 0.3);
height: 2px;
width: 50px;
top: 50%;
left: 0;
overflow: hidden;
}
.wind-line::after {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: white;
animation: wind-line-move 1s linear infinite;
}
@keyframes wind-line-move {
0% { transform: translateX(-100%); }
100% { transform: translateX(100%); }
}
/* Rain Animation Styles */
.raindrop {
position: absolute;
background-color: rgba(0, 0, 255, 0.7);
width: 2px;
height: 10px;
border-radius: 0 0 2px 2px;
animation: rain-fall 0.5s linear infinite;
}
@keyframes rain-fall {
0% { transform: translateY(-20px); opacity: 0.8; }
100% { transform: translateY(150px); opacity: 0; }
}
.puddle {
position: absolute;
bottom: 0;
left: 20%;
width: 60%;
height: 10px;
background-color: rgba(0, 0, 255, 0.5);
border-radius: 50% 50% 0 0;
opacity: 0;
animation: puddle-form 3s ease-out forwards;
}
@keyframes puddle-form {
0% { opacity: 0; height: 0px; }
100% { opacity: 1; height: 10px; }
}
/* Sun Animation Styles */
.sun {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
width: 50px;
height: 50px;
background-color: yellow;
border-radius: 50%;
box-shadow: 0 0 20px yellow;
}
.sun-ray {
position: absolute;
background-color: yellow;
opacity: 0.8;
border-radius: 5px;
animation: sun-rays-rotate 10s linear infinite;
}
.sun-ray:nth-child(1) { width: 2px; height: 20px; top: 5px; left: 50%; transform: translateX(-50%); }
.sun-ray:nth-child(2) { width: 20px; height: 2px; top: 50%; left: 5px; transform: translateY(-50%); }
.sun-ray:nth-child(3) { width: 2px; height: 20px; top: 5px; left: 50%; transform: translateX(-50%) rotate(45deg); }
.sun-ray:nth-child(4) { width: 2px; height: 20px; top: 5px; left: 50%; transform: translateX(-50%) rotate(-45deg); }
.sun-ray:nth-child(5) { width: 20px; height: 2px; top: 50%; left: 5px; transform: translateY(-50%) rotate(90deg); }
.sun-ray:nth-child(6) { width: 20px; height: 2px; top: 50%; left: 5px; transform: translateY(-50%) rotate(-90deg); }
.sun-ray:nth-child(7) { width: 2px; height: 20px; top: 5px; left: 50%; transform: translateX(-50%) rotate(135deg); }
.sun-ray:nth-child(8) { width: 2px; height: 20px; top: 5px; left: 50%; transform: translateX(-50%) rotate(-135deg); }
@keyframes sun-rays-rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
/* Snow Animation Styles */
.snowflake {
position: absolute;
background-color: white;
width: 5px;
height: 5px;
border-radius: 50%;
opacity: 0.7;
animation: snow-fall 6s linear infinite;
}
@keyframes snow-fall {
0% { transform: translateY(-20px) translateX(0); opacity: 0.7; }
50% { opacity: 1;}
100% { transform: translateY(150px) translateX(20px); opacity: 0; }
}
.snow-ground {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 20px;
background-color: white;
border-radius: 10px 10px 0 0;
opacity: 0.8;
}
/* Weather Condition Specific Styles and Animations */
/* Wind Weather Card */
.weather-card.wind .animation-container {
background: linear-gradient(to bottom, #87CEEB, #E0F7FA); /* Light blue sky */
}
.weather-card.wind .cloud {
animation: wind-animation 15s linear infinite;
}
.weather-card.wind .cloud:nth-child(2) { animation-delay: 5s; top: 40px; left: 30%; width: 70px; height: 35px; }
.weather-card.wind .cloud:nth-child(3) { animation-delay: 10s; top: 10px; left: 60%; width: 50px; height: 25px; }
.weather-card.wind .tree {
left: 70%;
animation: sway-tree 3s ease-in-out infinite;
}
.weather-card.wind .wind-line:nth-child(1) { top: 30px; left: 10%; }
.weather-card.wind .wind-line:nth-child(2) { top: 60px; left: 40%; }
/* Rain Weather Card */
.weather-card.rain .animation-container {
background: linear-gradient(to bottom, #778899, #B0C4DE); /* Gray sky */
}
.weather-card.rain .raindrop {
top: -10px;
left: calc(10% + var(--drop-pos) * 80%); /* Distribute raindrops horizontally */
animation-delay: calc(var(--drop-delay) * 0.5s);
}
.weather-card.rain .puddle {
animation-delay: 1s;
}
/* Sun Weather Card */
.weather-card.sun .animation-container {
background: linear-gradient(to bottom, #FFD700, #FFA500); /* Yellow/Orange sky */
}
.weather-card.sun .sun {
/* Sun is already styled generally */
}
/* Snow Weather Card */
.weather-card.snow .animation-container {
background: linear-gradient(to bottom, #E0F7FA, white); /* Very light blue to white sky */
}
.weather-card.snow .snowflake {
top: -10px;
left: calc(5% + var(--flake-pos) * 90%); /* Distribute snowflakes horizontally */
animation-delay: calc(var(--flake-delay) * 1s);
animation-duration: calc(var(--flake-duration) * 4s + 2s); /* Vary speed */
}
.weather-card.snow .snow-ground {
/* Snow ground is already styled generally */
}
</style>
</head>
<body>
<div class="weather-container">
<!-- Wind Weather Card -->
<div class="weather-card wind">
<h2>Windy</h2>
<div class="animation-container">
<div class="cloud" style="left: 10%;"></div>
<div class="cloud"></div>
<div class="cloud" style="left: 80%;"></div>
<div class="tree"></div>
<div class="wind-line"></div>
<div class="wind-line" style="animation-delay: 0.5s;"></div>
</div>
<div class="weather-info">
<p>Location: Windy Hills</p>
<p>Temperature: 15°C</p>
<p>Condition: Breezy</p>
<p>Wind Speed: 30 km/h</p>
<p>Humidity: 60%</p>
</div>
</div>
<!-- Rain Weather Card -->
<div class="weather-card rain">
<h2>Rainy</h2>
<div class="animation-container">
<div class="raindrop" style="--drop-pos: 0.1; --drop-delay: 0;"></div>
<div class="raindrop" style="--drop-pos: 0.3; --drop-delay: 0.2;"></div>
<div class="raindrop" style="--drop-pos: 0.5; --drop-delay: 0.4;"></div>
<div class="raindrop" style="--drop-pos: 0.7; --drop-delay: 0.1;"></div>
<div class="raindrop" style="--drop-pos: 0.9; --drop-delay: 0.3;"></div>
<div class="puddle"></div>
</div>
<div class="weather-info">
<p>Location: Rainy Valley</p>
<p>Temperature: 10°C</p>
<p>Condition: Light Rain</p>
<p>Precipitation: 5 mm</p>
<p>Humidity: 95%</p>
</div>
</div>
<!-- Sun Weather Card -->
<div class="weather-card sun">
<h2>Sunny</h2>
<div class="animation-container">
<div class="sun"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
</div>
<div class="weather-info">
<p>Location: Sunny Beach</p>
<p>Temperature: 28°C</p>
<p>Condition: Clear Sky</p>
<p>UV Index: High</p>
<p>Humidity: 40%</p>
</div>
</div>
<!-- Snow Weather Card -->
<div class="weather-card snow">
<h2>Snowy</h2>
<div class="animation-container">
<div class="snowflake" style="--flake-pos: 0.1; --flake-delay: 0; --flake-duration: 1;"></div>
<div class="snowflake" style="--flake-pos: 0.3; --flake-delay: 0.5; --flake-duration: 2;"></div>
<div class="snowflake" style="--flake-pos: 0.5; --flake-delay: 1; --flake-duration: 1.5;"></div>
<div class="snowflake" style="--flake-pos: 0.7; --flake-delay: 0.2; --flake-duration: 0.8;"></div>
<div class="snowflake" style="--flake-pos: 0.9; --flake-delay: 0.7; --flake-duration: 2.5;"></div>
<div class="snow-ground"></div>
</div>
<div class="weather-info">
<p>Location: Snowy Mountain</p>
<p>Temperature: -5°C</p>
<p>Condition: Snowfall</p>
<p>Snow Depth: 10 cm</p>
<p>Humidity: 80%</p>
</div>
</div>
</div>
<script>
// JavaScript for dynamic switching (if needed later - currently cards are side-by-side as requested)
// Example function structure for potential dynamic card update:
/*
function changeWeather(condition) {
const card = document.querySelector('.weather-card'); // Or target specific card if needed
card.className = 'weather-card ' + condition; // Update class for styling and animations
// Update weather information text content based on condition
if (condition === 'wind') {
// Update text content for wind condition
} else if (condition === 'rain') {
// Update text content for rain condition
} // ... and so on for other conditions
}
// Example buttons to trigger changeWeather
// <button onclick="changeWeather('wind')">Wind</button>
// <button onclick="changeWeather('rain')">Rain</button>
// ...
*/
</script>
</body>
</html>