Create a single HTML file containing CSS and JavaScript to generate an animated weather…
- User
Create a single HTML file containing CSS and JavaScript to generate an animated weather card with detailed weather information. The card should visually represent the following weather conditions with distinct animations: Wind: (e.g., moving clouds, swaying trees, or wind lines) Rain: (e.g., falling raindrops, puddles forming) Sun: (e.g., shining rays, bright background) Snow: (e.g., falling snowflakes, snow accumulating) Show all the weather card side by side The card should have a dark background. Provide all the HTML, CSS, and JavaScript code within this single file. The JavaScript should include a way to switch between the different weather conditions (e.g., a function or a set of buttons) to demonstrate the animations for each.
- Assistant
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Animated Weather Cards</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { background: #181c25; min-height: 100vh; margin: 0; font-family: 'Segoe UI', Arial, sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; color: #f0f0f0; } h1 { margin-top: 32px; margin-bottom: 16px; font-weight: 600; letter-spacing: 1px; } .weather-cards-container { display: flex; gap: 32px; margin: 32px 0; flex-wrap: wrap; justify-content: center; } .weather-card { background: #23283a; border-radius: 24px; box-shadow: 0 6px 32px rgba(0,0,0,0.25); width: 260px; min-height: 380px; padding: 24px 20px 20px 20px; display: flex; flex-direction: column; align-items: center; position: relative; overflow: hidden; transition: box-shadow 0.2s; } .weather-card:hover { box-shadow: 0 12px 40px rgba(0,0,0,0.35); } .weather-title { font-size: 1.3rem; font-weight: 500; margin-bottom: 8px; letter-spacing: 1px; text-align: center; } .weather-details { margin-top: 18px; width: 100%; font-size: 1.05rem; letter-spacing: 0.2px; } .weather-details span { display: block; margin-bottom: 6px; color: #b0b8d0; } .weather-anim { width: 120px; height: 120px; margin-top: 8px; margin-bottom: 8px; position: relative; display: flex; align-items: center; justify-content: center; } /* Sun Animation */ .sun { position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; background: radial-gradient(circle at 60% 40%, #ffe066 70%, #ffd43b 100%); border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 0 32px 8px #ffe06688; z-index: 2; animation: sun-glow 2.5s infinite alternate; } @keyframes sun-glow { 0% { box-shadow: 0 0 32px 8px #ffe06688; } 100% { box-shadow: 0 0 48px 16px #ffe066cc; } } .sun-rays { position: absolute; left: 50%; top: 50%; width: 90px; height: 90px; transform: translate(-50%, -50%); z-index: 1; pointer-events: none; } .sun-ray { position: absolute; width: 6px; height: 28px; background: linear-gradient(to bottom, #ffe066 80%, #ffd43b 100%); left: 50%; top: 50%; border-radius: 3px; transform-origin: center bottom; opacity: 0.7; animation: sun-ray-anim 2s linear infinite; } /* 8 rays, rotate each by 45deg */ .sun-ray:nth-child(1) { transform: rotate(0deg) translate(-50%, -100%); animation-delay: 0s;} .sun-ray:nth-child(2) { transform: rotate(45deg) translate(-50%, -100%); animation-delay: 0.2s;} .sun-ray:nth-child(3) { transform: rotate(90deg) translate(-50%, -100%); animation-delay: 0.4s;} .sun-ray:nth-child(4) { transform: rotate(135deg) translate(-50%, -100%); animation-delay: 0.6s;} .sun-ray:nth-child(5) { transform: rotate(180deg) translate(-50%, -100%); animation-delay: 0.8s;} .sun-ray:nth-child(6) { transform: rotate(225deg) translate(-50%, -100%); animation-delay: 1.0s;} .sun-ray:nth-child(7) { transform: rotate(270deg) translate(-50%, -100%); animation-delay: 1.2s;} .sun-ray:nth-child(8) { transform: rotate(315deg) translate(-50%, -100%); animation-delay: 1.4s;} @keyframes sun-ray-anim { 0% { opacity: 0.7; } 50% { opacity: 1; } 100% { opacity: 0.7; } } /* Rain Animation */ .rain-cloud { position: absolute; left: 50%; top: 38%; width: 70px; height: 36px; transform: translate(-50%, -50%); z-index: 2; } .cloud-part { position: absolute; background: #b0b8d0; border-radius: 50%; } .cloud-part.big { width: 38px; height: 38px; left: 10px; top: 0; } .cloud-part.small { width: 28px; height: 28px; left: 32px; top: 8px; } .cloud-part.tiny { width: 18px; height: 18px; left: 0px; top: 16px; } .rain-drops { position: absolute; left: 50%; top: 70%; width: 60px; height: 50px; transform: translate(-50%, 0); z-index: 1; pointer-events: none; } .raindrop { position: absolute; width: 4px; height: 18px; background: linear-gradient(to bottom, #4dabf7 60%, #228be6 100%); border-radius: 2px; opacity: 0.7; animation: raindrop-fall 1.2s linear infinite; } .raindrop:nth-child(1) { left: 6px; animation-delay: 0s;} .raindrop:nth-child(2) { left: 18px; animation-delay: 0.3s;} .raindrop:nth-child(3) { left: 30px; animation-delay: 0.6s;} .raindrop:nth-child(4) { left: 42px; animation-delay: 0.9s;} .raindrop:nth-child(5) { left: 54px; animation-delay: 0.5s;} @keyframes raindrop-fall { 0% { top: 0; opacity: 0.7;} 80% { opacity: 0.8;} 100% { top: 32px; opacity: 0;} } .puddle { position: absolute; left: 50%; top: 92%; width: 38px; height: 10px; background: radial-gradient(ellipse at center, #4dabf7 60%, #228be6 100%); border-radius: 50%; transform: translate(-50%, -50%) scaleX(1); opacity: 0.7; animation: puddle-grow 2.5s infinite alternate; z-index: 0; } @keyframes puddle-grow { 0% { transform: translate(-50%, -50%) scaleX(0.8);} 100% { transform: translate(-50%, -50%) scaleX(1.1);} } /* Wind Animation */ .wind-cloud { position: absolute; left: 50%; top: 38%; width: 70px; height: 36px; transform: translate(-50%, -50%); z-index: 2; animation: wind-cloud-move 2.5s ease-in-out infinite alternate; } @keyframes wind-cloud-move { 0% { left: 45%; } 100% { left: 55%; } } .wind-lines { position: absolute; left: 50%; top: 80%; width: 80px; height: 40px; transform: translate(-50%, 0); z-index: 1; pointer-events: none; } .wind-line { position: absolute; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #b0b8d0 60%, #dee2e6 100%); opacity: 0.7; animation: wind-line-move 1.8s linear infinite; } .wind-line:nth-child(1) { width: 48px; top: 4px; left: 0; animation-delay: 0s; } .wind-line:nth-child(2) { width: 38px; top: 18px; left: 10px; animation-delay: 0.5s; } .wind-line:nth-child(3) { width: 28px; top: 32px; left: 20px; animation-delay: 1s; } @keyframes wind-line-move { 0% { opacity: 0.7; left: 0;} 80% { opacity: 1;} 100% { opacity: 0; left: 60px;} } .tree { position: absolute; left: 50%; top: 90%; width: 32px; height: 48px; transform: translate(-50%, -100%); z-index: 3; pointer-events: none; } .tree-trunk { position: absolute; left: 14px; bottom: 0; width: 4px; height: 22px; background: #795548; border-radius: 2px; } .tree-leaves { position: absolute; left: 0; bottom: 16px; width: 32px; height: 24px; background: #43aa8b; border-radius: 16px 16px 16px 16px / 18px 18px 18px 18px; transform-origin: bottom center; animation: tree-sway 1.8s ease-in-out infinite alternate; box-shadow: 0 0 8px 2px #43aa8b44; } @keyframes tree-sway { 0% { transform: rotate(-7deg);} 100% { transform: rotate(10deg);} } /* Snow Animation */ .snow-cloud { position: absolute; left: 50%; top: 38%; width: 70px; height: 36px; transform: translate(-50%, -50%); z-index: 2; } .snowflakes { position: absolute; left: 50%; top: 70%; width: 60px; height: 50px; transform: translate(-50%, 0); z-index: 1; pointer-events: none; } .snowflake { position: absolute; width: 12px; height: 12px; opacity: 0.8; animation: snowflake-fall 2.5s linear infinite; font-size: 1.1em; color: #fff; filter: drop-shadow(0 0 2px #fff8); user-select: none; } .snowflake:nth-child(1) { left: 6px; animation-delay: 0s;} .snowflake:nth-child(2) { left: 18px; animation-delay: 0.7s;} .snowflake:nth-child(3) { left: 30px; animation-delay: 1.2s;} .snowflake:nth-child(4) { left: 42px; animation-delay: 1.7s;} .snowflake:nth-child(5) { left: 54px; animation-delay: 0.9s;} @keyframes snowflake-fall { 0% { top: 0; opacity: 0.8; transform: scale(1) rotate(0deg);} 80% { opacity: 1;} 100% { top: 32px; opacity: 0.2; transform: scale(1.2) rotate(30deg);} } .snow-accum { position: absolute; left: 50%; top: 92%; width: 38px; height: 10px; background: radial-gradient(ellipse at center, #fff 80%, #dee2e6 100%); border-radius: 50%; transform: translate(-50%, -50%) scaleX(1); opacity: 0.8; animation: snow-accum-grow 2.5s infinite alternate; z-index: 0; } @keyframes snow-accum-grow { 0% { transform: translate(-50%, -50%) scaleX(0.8);} 100% { transform: translate(-50%, -50%) scaleX(1.1);} } /* Responsive */ @media (max-width: 1100px) { .weather-cards-container { gap: 18px; } .weather-card { width: 220px; min-height: 340px; padding: 18px 10px 14px 10px; } .weather-anim { width: 90px; height: 90px; } } @media (max-width: 900px) { .weather-cards-container { flex-wrap: wrap; } .weather-card { width: 90vw; max-width: 320px; } } .switch-btns { display: flex; gap: 12px; margin-bottom: 12px; } .switch-btn { background: #23283a; color: #ffe066; border: none; border-radius: 16px; padding: 8px 18px; font-size: 1rem; font-weight: 500; cursor: pointer; transition: background 0.2s, color 0.2s; outline: none; box-shadow: 0 2px 8px #0002; } .switch-btn.active, .switch-btn:hover { background: #ffe066; color: #23283a; } </style> </head> <body> <h1>Animated Weather Cards</h1> <div class="switch-btns"> <button class="switch-btn active" data-weather="all">Show All</button> <button class="switch-btn" data-weather="sun">Sun</button> <button class="switch-btn" data-weather="rain">Rain</button> <button class="switch-btn" data-weather="wind">Wind</button> <button class="switch-btn" data-weather="snow">Snow</button> </div> <div class="weather-cards-container" id="weatherCardsContainer"> <!-- Weather cards will be injected here --> </div> <script> // Weather data for demonstration const weatherData = [ { type: 'sun', title: 'Sunny', details: { Temperature: '28°C', Humidity: '35%', Wind: '8 km/h', UV: 'High', Description: 'Clear sky, bright sunshine' } }, { type: 'rain', title: 'Rainy', details: { Temperature: '19°C', Humidity: '88%', Wind: '12 km/h', UV: 'Low', Description: 'Steady rain, possible puddles' } }, { type: 'wind', title: 'Windy', details: { Temperature: '22°C', Humidity: '50%', Wind: '32 km/h', UV: 'Moderate', Description: 'Strong gusts, swaying trees' } }, { type: 'snow', title: 'Snowy', details: { Temperature: '-3°C', Humidity: '78%', Wind: '10 km/h', UV: 'Low', Description: 'Snowfall, snow accumulation' } } ]; // Animation SVG/HTML for each weather type function getWeatherAnim(type) { switch(type) { case 'sun': return ` <div class="sun"></div> <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> `; case 'rain': return ` <div class="rain-cloud"> <div class="cloud-part big"></div> <div class="cloud-part small"></div> <div class="cloud-part tiny"></div> </div> <div class="rain-drops"> <div class="raindrop"></div> <div class="raindrop"></div> <div class="raindrop"></div> <div class="raindrop"></div> <div class="raindrop"></div> </div> <div class="puddle"></div> `; case 'wind': return ` <div class="wind-cloud"> <div class="cloud-part big"></div> <div class="cloud-part small"></div> <div class="cloud-part tiny"></div> </div> <div class="wind-lines"> <div class="wind-line"></div> <div class="wind-line"></div> <div class="wind-line"></div> </div> <div class="tree"> <div class="tree-trunk"></div> <div class="tree-leaves"></div> </div> `; case 'snow': return ` <div class="snow-cloud"> <div class="cloud-part big"></div> <div class="cloud-part small"></div> <div class="cloud-part tiny"></div> </div> <div class="snowflakes"> <div class="snowflake">*</div> <div class="snowflake">❄</div> <div class="snowflake">*</div> <div class="snowflake">❄</div> <div class="snowflake">*</div> </div> <div class="snow-accum"></div> `; default: return ''; } } // Render weather cards function renderWeatherCards(filterType = 'all') { const container = document.getElementById('weatherCardsContainer'); container.innerHTML = ''; let filtered = weatherData; if (filterType !== 'all') { filtered = weatherData.filter(w => w.type === filterType); } filtered.forEach(w => { const card = document.createElement('div'); card.className = 'weather-card'; card.innerHTML = ` <div class="weather-title">${w.title}</div> <div class="weather-anim">${getWeatherAnim(w.type)}</div> <div class="weather-details"> <span><strong>Temperature:</strong> ${w.details.Temperature}</span> <span><strong>Humidity:</strong> ${w.details.Humidity}</span> <span><strong>Wind:</strong> ${w.details.Wind}</span> <span><strong>UV Index:</strong> ${w.details.UV}</span> <span><strong>Description:</strong> ${w.details.Description}</span> </div> `; container.appendChild(card); }); } // Button switching logic document.querySelectorAll('.switch-btn').forEach(btn => { btn.addEventListener('click', function() { document.querySelectorAll('.switch-btn').forEach(b => b.classList.remove('active')); this.classList.add('active'); const type = this.getAttribute('data-weather'); renderWeatherCards(type); }); }); // Initial render renderWeatherCards('all'); </script> </body> </html>How it works:
- All code is in one HTML file.
- Four animated weather cards (Sun, Rain, Wind, Snow) are shown side by side by default.
- Distinct animations for each weather type using only HTML/CSS (no images).
- Switch buttons at the top let you show all cards or just one type to focus on its animation.
- Dark background and modern card design.
- Responsive for smaller screens.
Just copy, save as
.html, and open in your browser!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.