<!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: 'Arial', sans-serif;
background-color: #1a1a2e;
color: white;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 20px;
margin-top: 20px;
}
.weather-card {
width: 250px;
height: 350px;
border-radius: 15px;
overflow: hidden;
position: relative;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}
.card-content {
padding: 20px;
position: relative;
z-index: 2;
height: 100%;
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: space-between;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.7));
}
.location {
font-size: 1.2em;
font-weight: bold;
margin-bottom: 5px;
}
.date {
font-size: 0.9em;
opacity: 0.8;
margin-bottom: 15px;
}
.temperature {
font-size: 2.5em;
font-weight: bold;
margin-bottom: 10px;
}
.weather-type {
font-size: 1.2em;
margin-bottom: 15px;
}
.details {
display: flex;
justify-content: space-between;
}
.detail {
text-align: center;
}
.detail-value {
font-size: 1.2em;
font-weight: bold;
}
.detail-label {
font-size: 0.8em;
opacity: 0.8;
}
/* Wind Animation */
.wind-card {
background: linear-gradient(to bottom, #2c3e50, #1a1a2e);
}
.cloud {
position: absolute;
background: rgba(255, 255, 255, 0.7);
border-radius: 50%;
z-index: 1;
}
.wind-line {
position: absolute;
height: 2px;
background: rgba(255, 255, 255, 0.3);
z-index: 1;
}
/* Rain Animation */
.rain-card {
background: linear-gradient(to bottom, #34495e, #2c3e50);
}
.raindrop {
position: absolute;
width: 2px;
background: rgba(255, 255, 255, 0.6);
z-index: 1;
border-radius: 50% 50% 0 0;
}
/* Sun Animation */
.sun-card {
background: linear-gradient(to bottom, #f39c12, #e67e22);
}
.sun {
position: absolute;
width: 80px;
height: 80px;
background: #f1c40f;
border-radius: 50%;
top: 40px;
right: 40px;
box-shadow: 0 0 40px #f1c40f;
z-index: 1;
}
.sun-ray {
position: absolute;
background: rgba(255, 255, 255, 0.4);
z-index: 1;
}
/* Snow Animation */
.snow-card {
background: linear-gradient(to bottom, #7f8c8d, #2c3e50);
}
.snowflake {
position: absolute;
color: white;
font-size: 10px;
z-index: 1;
opacity: 0.8;
}
.controls {
margin-bottom: 20px;
}
button {
background-color: #3498db;
color: white;
border: none;
padding: 10px 15px;
margin: 5px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #2980b9;
}
button.active {
background-color: #e74c3c;
}
</style>
</head>
<body>
<h1>Animated Weather Cards</h1>
<div class="container">
<!-- Wind Card -->
<div class="weather-card wind-card" id="wind-card">
<div class="card-content">
<div>
<div class="location">Chicago, IL</div>
<div class="date">Monday, Oct 16</div>
</div>
<div>
<div class="temperature">18°C</div>
<div class="weather-type">Windy</div>
</div>
<div class="details">
<div class="detail">
<div class="detail-value">35 km/h</div>
<div class="detail-label">Wind</div>
</div>
<div class="detail">
<div class="detail-value">65%</div>
<div class="detail-label">Humidity</div>
</div>
<div class="detail">
<div class="detail-value">1015 hPa</div>
<div class="detail-label">Pressure</div>
</div>
</div>
</div>
</div>
<!-- Rain Card -->
<div class="weather-card rain-card" id="rain-card">
<div class="card-content">
<div>
<div class="location">Seattle, WA</div>
<div class="date">Monday, Oct 16</div>
</div>
<div>
<div class="temperature">14°C</div>
<div class="weather-type">Rainy</div>
</div>
<div class="details">
<div class="detail">
<div class="detail-value">10 km/h</div>
<div class="detail-label">Wind</div>
</div>
<div class="detail">
<div class="detail-value">85%</div>
<div class="detail-label">Humidity</div>
</div>
<div class="detail">
<div class="detail-value">1008 hPa</div>
<div class="detail-label">Pressure</div>
</div>
</div>
</div>
</div>
<!-- Sun Card -->
<div class="weather-card sun-card" id="sun-card">
<div class="card-content">
<div>
<div class="location">Miami, FL</div>
<div class="date">Monday, Oct 16</div>
</div>
<div>
<div class="temperature">32°C</div>
<div class="weather-type">Sunny</div>
</div>
<div class="details">
<div class="detail">
<div class="detail-value">8 km/h</div>
<div class="detail-label">Wind</div>
</div>
<div class="detail">
<div class="detail-value">45%</div>
<div class="detail-label">Humidity</div>
</div>
<div class="detail">
<div class="detail-value">1020 hPa</div>
<div class="detail-label">Pressure</div>
</div>
</div>
</div>
</div>
<!-- Snow Card -->
<div class="weather-card snow-card" id="snow-card">
<div class="card-content">
<div>
<div class="location">Denver, CO</div>
<div class="date">Monday, Oct 16</div>
</div>
<div>
<div class="temperature">-2°C</div>
<div class="weather-type">Snowy</div>
</div>
<div class="details">
<div class="detail">
<div class="detail-value">15 km/h</div>
<div class="detail-label">Wind</div>
</div>
<div class="detail">
<div class="detail-value">75%</div>
<div class="detail-label">Humidity</div>
</div>
<div class="detail">
<div class="detail-value">1012 hPa</div>
<div class="detail-label">Pressure</div>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Wind Animation
const windCard = document.getElementById('wind-card');
// Create clouds
for (let i = 0; i < 8; i++) {
const cloud = document.createElement('div');
cloud.className = 'cloud';
cloud.style.width = Math.random() * 60 + 20 + 'px';
cloud.style.height = Math.random() * 30 + 10 + 'px';
cloud.style.top = Math.random() * 300 + 'px';
cloud.style.left = -100 + 'px';
cloud.style.opacity = Math.random() * 0.5 + 0.3;
cloud.style.animationDuration = Math.random() * 10 + 10 + 's';
cloud.style.animation = `moveCloud ${Math.random() * 10 + 15}s linear infinite`;
windCard.appendChild(cloud);
}
// Create wind lines
for (let i = 0; i < 15; i++) {
const windLine = document.createElement('div');
windLine.className = 'wind-line';
windLine.style.width = Math.random() * 50 + 20 + 'px';
windLine.style.top = Math.random() * 350 + 'px';
windLine.style.left = -50 + 'px';
windLine.style.animation = `moveWindLine ${Math.random() * 3 + 2}s linear infinite`;
windCard.appendChild(windLine);
}
// Rain Animation
const rainCard = document.getElementById('rain-card');
// Create raindrops
for (let i = 0; i < 80; i++) {
const raindrop = document.createElement('div');
raindrop.className = 'raindrop';
raindrop.style.height = Math.random() * 15 + 5 + 'px';
raindrop.style.left = Math.random() * 250 + 'px';
raindrop.style.top = -20 + 'px';
raindrop.style.animationDelay = Math.random() * 5 + 's';
raindrop.style.animation = `rain ${Math.random() * 1 + 1}s linear infinite`;
rainCard.appendChild(raindrop);
}
// Sun Animation
const sunCard = document.getElementById('sun-card');
// Create sun
const sun = document.createElement('div');
sun.className = 'sun';
sun.style.animation = 'pulse 3s infinite alternate';
sunCard.appendChild(sun);
// Create sun rays
for (let i = 0; i < 12; i++) {
const sunRay = document.createElement('div');
sunRay.className = 'sun-ray';
const angle = (i * 30) * (Math.PI / 180);
const length = 100;
sunRay.style.width = '2px';
sunRay.style.height = length + 'px';
sunRay.style.transformOrigin = 'bottom center';
sunRay.style.transform = `rotate(${i * 30}deg)`;
sunRay.style.top = '40px';
sunRay.style.right = '80px';
sunRay.style.animation = `pulse 3s infinite alternate ${i * 0.2}s`;
sunCard.appendChild(sunRay);
}
// Snow Animation
const snowCard = document.getElementById('snow-card');
// Create snowflakes
for (let i = 0; i < 50; i++) {
const snowflake = document.createElement('div');
snowflake.className = 'snowflake';
snowflake.innerHTML = '❄';
snowflake.style.left = Math.random() * 250 + 'px';
snowflake.style.top = -20 + 'px';
snowflake.style.fontSize = Math.random() * 10 + 5 + 'px';
snowflake.style.animation = `snow ${Math.random() * 5 + 5}s linear infinite`;
snowflake.style.animationDelay = Math.random() * 5 + 's';
snowCard.appendChild(snowflake);
}
// Add CSS animations
const style = document.createElement('style');
style.textContent = `
@keyframes moveCloud {
0% { left: -100px; }
100% { left: 300px; }
}
@keyframes moveWindLine {
0% { left: -50px; }
100% { left: 300px; }
}
@keyframes rain {
0% { top: -20px; opacity: 0; }
50% { opacity: 1; }
100% { top: 370px; opacity: 0.3; }
}
@keyframes pulse {
0% { transform: scale(1); opacity: 1; }
100% { transform: scale(1.1); opacity: 0.8; }
}
@keyframes snow {
0% {
top: -20px;
transform: translateX(0) rotate(0deg);
}
100% {
top: 370px;
transform: translateX(${Math.random() > 0.5 ? '+' : '-'}${Math.random() * 100}px) rotate(360deg);
}
}
`;
document.head.appendChild(style);
});
</script>
</body>
</html>
This HTML file creates four animated weather cards side by side, each representing a different weather condition:
- Wind Card: Features animated clouds and wind lines moving across the card
- Rain Card: Shows raindrops falling from top to bottom
- Sun Card: Displays a pulsing sun with radiating sun rays
- Snow Card: Features snowflakes falling with a slight drift and rotation
Each card includes: