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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.controls {
margin-bottom: 30px;
text-align: center;
}
.speed-control {
background: rgba(255, 255, 255, 0.9);
padding: 15px 25px;
border-radius: 25px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
.speed-control label {
font-weight: bold;
margin-right: 10px;
color: #333;
}
.speed-control select {
padding: 8px 15px;
border: none;
border-radius: 15px;
background: #fff;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
cursor: pointer;
}
.weather-container {
display: flex;
gap: 30px;
flex-wrap: wrap;
justify-content: center;
max-width: 1200px;
}
.weather-card {
width: 250px;
height: 350px;
border-radius: 20px;
position: relative;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
cursor: pointer;
transition: transform 0.3s ease;
}
.weather-card:hover {
transform: translateY(-10px);
}
.card-content {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 20px;
text-align: center;
}
.weather-title {
font-size: 24px;
font-weight: bold;
margin-bottom: 5px;
}
.weather-temp {
font-size: 18px;
opacity: 0.9;
}
/* Wind Card */
.wind-card {
background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
}
.wind-lines {
position: absolute;
width: 100%;
height: 100%;
}
.wind-line {
position: absolute;
height: 2px;
background: rgba(255, 255, 255, 0.6);
border-radius: 1px;
}
.wind-line:nth-child(1) {
width: 60px;
top: 20%;
left: -60px;
animation: windMove1 var(--speed, 3s) infinite linear;
}
.wind-line:nth-child(2) {
width: 80px;
top: 35%;
left: -80px;
animation: windMove2 var(--speed, 2.5s) infinite linear;
}
.wind-line:nth-child(3) {
width: 50px;
top: 50%;
left: -50px;
animation: windMove3 var(--speed, 3.5s) infinite linear;
}
.wind-line:nth-child(4) {
width: 70px;
top: 65%;
left: -70px;
animation: windMove1 var(--speed, 2.8s) infinite linear;
}
@keyframes windMove1 {
0% { left: -100px; }
100% { left: 100%; }
}
@keyframes windMove2 {
0% { left: -100px; }
100% { left: 100%; }
}
@keyframes windMove3 {
0% { left: -100px; }
100% { left: 100%; }
}
.cloud {
position: absolute;
background: rgba(255, 255, 255, 0.8);
border-radius: 50px;
}
.cloud:before,
.cloud:after {
content: '';
position: absolute;
background: rgba(255, 255, 255, 0.8);
border-radius: 50px;
}
.cloud1 {
width: 80px;
height: 40px;
top: 15%;
left: -80px;
animation: cloudMove var(--speed, 8s) infinite linear;
}
.cloud1:before {
width: 50px;
height: 50px;
top: -25px;
left: 10px;
}
.cloud1:after {
width: 60px;
height: 40px;
top: -15px;
right: 10px;
}
@keyframes cloudMove {
0% { left: -100px; }
100% { left: 100%; }
}
/* Rain Card */
.rain-card {
background: linear-gradient(135deg, #636e72 0%, #2d3436 100%);
}
.rain-container {
position: absolute;
width: 100%;
height: 100%;
}
.raindrop {
position: absolute;
width: 2px;
height: 15px;
background: rgba(173, 216, 230, 0.8);
border-radius: 0 0 50% 50%;
animation: rainFall var(--speed, 1s) infinite linear;
}
@keyframes rainFall {
0% {
top: -20px;
opacity: 1;
}
100% {
top: 100%;
opacity: 0.3;
}
}
/* Sun Card */
.sun-card {
background: linear-gradient(135deg, #fdcb6e 0%, #e17055 100%);
}
.sun {
position: absolute;
width: 80px;
height: 80px;
background: #f39c12;
border-radius: 50%;
top: 30%;
left: 50%;
transform: translateX(-50%);
box-shadow: 0 0 30px rgba(243, 156, 18, 0.6);
animation: sunPulse var(--speed, 3s) infinite ease-in-out;
}
.sun-ray {
position: absolute;
width: 4px;
height: 20px;
background: #f39c12;
border-radius: 2px;
top: 50%;
left: 50%;
transform-origin: 2px 40px;
}
.sun-ray:nth-child(1) { transform: translate(-50%, -50%) rotate(0deg); }
.sun-ray:nth-child(2) { transform: translate(-50%, -50%) rotate(45deg); }
.sun-ray:nth-child(3) { transform: translate(-50%, -50%) rotate(90deg); }
.sun-ray:nth-child(4) { transform: translate(-50%, -50%) rotate(135deg); }
.sun-ray:nth-child(5) { transform: translate(-50%, -50%) rotate(180deg); }
.sun-ray:nth-child(6) { transform: translate(-50%, -50%) rotate(225deg); }
.sun-ray:nth-child(7) { transform: translate(-50%, -50%) rotate(270deg); }
.sun-ray:nth-child(8) { transform: translate(-50%, -50%) rotate(315deg); }
@keyframes sunPulse {
0%, 100% { transform: translateX(-50%) scale(1); }
50% { transform: translateX(-50%) scale(1.1); }
}
.sun-rays {
position: absolute;
width: 120px;
height: 120px;
top: 30%;
left: 50%;
transform: translateX(-50%);
animation: sunRotate var(--speed, 10s) infinite linear;
}
@keyframes sunRotate {
0% { transform: translateX(-50%) rotate(0deg); }
100% { transform: translateX(-50%) rotate(360deg); }
}
/* Snow Card */
.snow-card {
background: linear-gradient(135deg, #ddd6fe 0%, #8b5cf6 100%);
}
.snow-container {
position: absolute;
width: 100%;
height: 100%;
}
.snowflake {
position: absolute;
color: white;
font-size: 14px;
animation: snowFall var(--speed, 3s) infinite linear;
opacity: 0.8;
}
@keyframes snowFall {
0% {
top: -20px;
opacity: 1;
}
100% {
top: 100%;
opacity: 0;
}
}
.snow-ground {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 20px;
background: rgba(255, 255, 255, 0.9);
border-radius: 10px 10px 0 0;
animation: snowAccumulate var(--speed, 5s) infinite ease-in-out;
}
@keyframes snowAccumulate {
0%, 100% { height: 20px; }
50% { height: 25px; }
}
/* Speed classes */
.slow { --speed: 6s; }
.normal { --speed: 3s; }
.fast { --speed: 1.5s; }
</style>
</head>
<body>
<div class="controls">
<div class="speed-control">
<label for="speedSelect">Animation Speed:</label>
<select id="speedSelect">
<option value="slow">Slow</option>
<option value="normal" selected>Normal</option>
<option value="fast">Fast</option>
</select>
</div>
</div>
<div class="weather-container">
<!-- Wind Card -->
<div class="weather-card wind-card" id="windCard">
<div class="wind-lines">
<div class="wind-line"></div>
<div class="wind-line"></div>
<div class="wind-line"></div>
<div class="wind-line"></div>
</div>
<div class="cloud cloud1"></div>
<div class="card-content">
<div class="weather-title">Windy</div>
<div class="weather-temp">18°C</div>
</div>
</div>
<!-- Rain Card -->
<div class="weather-card rain-card" id="rainCard">
<div class="rain-container" id="rainContainer"></div>
<div class="card-content">
<div class="weather-title">Rainy</div>
<div class="weather-temp">12°C</div>
</div>
</div>
<!-- Sun Card -->
<div class="weather-card sun-card" id="sunCard">
<div class="sun-rays">
<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="sun"></div>
<div class="card-content">
<div class="weather-title">Sunny</div>
<div class="weather-temp">28°C</div>
</div>
</div>
<!-- Snow Card -->
<div class="weather-card snow-card" id="snowCard">
<div class="snow-container" id="snowContainer"></div>
<div class="snow-ground"></div>
<div class="card-content">
<div class="weather-title">Snowy</div>
<div class="weather-temp">-2°C</div>
</div>
</div>
</div>
<script>
// Speed control functionality
const speedSelect = document.getElementById('speedSelect');
const weatherCards = document.querySelectorAll('.weather-card');
speedSelect.addEventListener('change', function() {
const selectedSpeed = this.value;
weatherCards.forEach(card => {
card.className = card.className.replace(/\b(slow|normal|fast)\b/g, '');
card.classList.add(selectedSpeed);
});
});
// Initialize with normal speed
weatherCards.forEach(card => {
card.classList.add('normal');
});
// Generate raindrops
function createRaindrops() {
const rainContainer = document.getElementById('rainContainer');
const numberOfDrops = 50;
for (let i = 0; i < numberOfDrops; i++) {
const raindrop = document.createElement('div');
raindrop.className = 'raindrop';
raindrop.style.left = Math.random() * 100 + '%';
raindrop.style.animationDelay = Math.random() * 2 + 's';
raindrop.style.animationDuration = (Math.random() * 0.5 + 0.5) + 's';
rainContainer.appendChild(raindrop);
}
}
// Generate snowflakes
function createSnowflakes() {
const snowContainer = document.getElementById('snowContainer');
const numberOfFlakes = 30;
const snowflakeSymbols = ['❄', '❅', '❆'];
for (let i = 0; i < numberOfFlakes; i++) {
const snowflake = document.createElement('div');
snowflake.className = 'snowflake';
snowflake.textContent = snowflakeSymbols[Math.floor(Math.random() * snowflakeSymbols.length)];
snowflake.style.left = Math.random() * 100 + '%';
snowflake.style.animationDelay = Math.random() * 3 + 's';
snowflake.style.animationDuration = (Math.random() * 2 + 2) + 's';
snowflake.style.fontSize = (Math.random() * 10 + 10) + 'px';
snowContainer.appendChild(snowflake);
}
}
// Initialize animations
createRaindrops();
createSnowflakes();
// Add hover effects
weatherCards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-10px) scale(1.02)';
});
card.addEventListener('mousele