Act like a senior front-end developer and creative UI/UX animator. You have 15 years of…
- User
Act like a senior front-end developer and creative UI/UX animator. You have 15 years of experience creating immersive web components using HTML, CSS animations, and JavaScript interactions. You specialize in interactive single-page apps, and your work is known for its clean code, modular structure, and delightful user experience.
I want you to build a fully self-contained HTML page (a single .html file) that includes embedded CSS and JavaScript to showcase a visually appealing “Weather Animation Card Component”. This component should be functional, visually rich, and follow best practices in animation and interactivity.
🧩 Task Objective:
Build a complete responsive web page in a single HTML file (with inline CSS and JavaScript) that displays four weather animation cards side-by-side. Each card must animate a different weather condition: Wind, Rain, Sun, and Snow. Each animation should be distinct, engaging, and aesthetically consistent.
🧱 Step-by-Step Requirements:
- Page Setup
• Use a dark theme for the page background (e.g., gradients or subtle noise textures). • Ensure all HTML, CSS, and JavaScript are included inline (no external files). • Ensure responsive design: the cards should adapt from horizontal layout to vertical on small screens.
- Weather Cards Layout
• Create four weather cards, laid out horizontally using Flexbox or Grid. • Each card must have a title (e.g., “Windy”, “Rainy”, “Sunny”, “Snowy”) and a canvas/div where animations appear. • Use subtle shadows and borders to separate cards.
- Animation Details (One per Card)
Each weather card should have unique, smooth animations:
• Wind – Animate floating clouds, oscillating trees or grass, and dynamic wind lines (e.g., using SVG or CSS keyframes).
• Rain – Falling raindrops with random timing, splash effects when they hit a surface, puddle accumulation if possible.
• Sun – Pulsating rays, rotating or glowing sun with radial gradient, light flicker or warm transitions.
• Snow – Gently falling snowflakes with random drift, subtle snow accumulation on surfaces, frosty visual effects.
Use modern CSS animations or JavaScript Canvas where appropriate.
- Interaction (JS-Based)
• Add interactive buttons or toggles to switch between viewing one weather card at a time OR viewing all four side-by-side. • Provide a reusable JavaScript function (switchWeather(type)) to programmatically switch between weather types. • Ensure animation states pause/resume correctly on switching views.
- Code Quality Expectations
• Comment your HTML, CSS, and JavaScript thoroughly. • Use modular, readable CSS class naming conventions (e.g., BEM or similar). • Avoid excessive libraries – stick to vanilla JS and CSS (unless canvas or SVG usage justifies it).
🎯 Final Output:
Generate a complete, production-quality HTML file. The final output should be visually attractive, performance-optimized, animation-rich, and easy to extend.
Take a deep breath and work on this problem step-by-step.
- Assistant
Absolutely! Here’s a production-quality, fully self-contained HTML file for a responsive, animated Weather Card Component, as described. The code is modular, well-commented, and uses only vanilla HTML, CSS, and JavaScript (with Canvas and SVG where appropriate). The UI is dark-themed, responsive, and includes a toggle to switch between single and all-card views, with a reusable
switchWeather(type)function.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Animated Weather Card Component</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Weather Animation Card Component Author: Senior Front-End Developer (15+ yrs exp) Description: Responsive, interactive, animated weather cards (Wind, Rain, Sun, Snow) --> <style> /* ====== Base Styles & Dark Theme ====== */ html, body { height: 100%; margin: 0; padding: 0; font-family: 'Segoe UI', 'Roboto', Arial, sans-serif; background: linear-gradient(135deg, #23243a 0%, #1a1b2b 100%); min-height: 100vh; color: #f3f6fa; box-sizing: border-box; } body { display: flex; flex-direction: column; align-items: center; min-height: 100vh; background-image: url('data:image/svg+xml;utf8,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><circle fill="rgba(255,255,255,0.01)" cx="50" cy="50" r="2"/></svg>'); background-repeat: repeat; } h1 { margin-top: 2rem; font-size: 2.2rem; letter-spacing: 0.05em; font-weight: 700; text-align: center; color: #f3f6fa; text-shadow: 0 2px 8px #0006; } /* ====== Layout: Weather Cards Container ====== */ .weather-cards { display: flex; flex-wrap: wrap; gap: 2rem; margin: 2rem 0; justify-content: center; width: 100%; max-width: 1200px; transition: all 0.4s cubic-bezier(.4,0,.2,1); } .weather-cards--single { flex-wrap: nowrap; justify-content: center; gap: 0; } /* ====== Weather Card Styles ====== */ .weather-card { background: linear-gradient(135deg, #23243a 60%, #23243a 100%); border-radius: 1.5rem; box-shadow: 0 6px 32px 0 #0004, 0 1.5px 6px 0 #0002; border: 1.5px solid #2e2f4a; min-width: 260px; max-width: 320px; flex: 1 1 260px; display: flex; flex-direction: column; align-items: center; padding: 1.5rem 1rem 1.2rem 1rem; position: relative; overflow: hidden; transition: box-shadow 0.3s; z-index: 1; } .weather-card__title { font-size: 1.3rem; font-weight: 600; margin-bottom: 1.1rem; letter-spacing: 0.04em; color: #f3f6fa; text-shadow: 0 1px 4px #0003; z-index: 2; } .weather-card__anim { width: 180px; height: 140px; margin-bottom: 0.7rem; position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; } .weather-card__footer { font-size: 0.98rem; color: #bfc6e0; opacity: 0.7; margin-top: auto; text-align: center; z-index: 2; } .weather-card:not(:last-child) { /* For subtle separation on large screens */ margin-right: 0; } .weather-card__border { position: absolute; inset: 0; border-radius: 1.5rem; pointer-events: none; border: 2px solid transparent; transition: border-color 0.3s; z-index: 3; } .weather-card--active .weather-card__border { border-color: #4fd1c5; box-shadow: 0 0 0 2px #4fd1c588; } /* ====== Responsive Layout ====== */ @media (max-width: 900px) { .weather-cards { gap: 1.2rem; } .weather-card { min-width: 220px; max-width: 100vw; } } @media (max-width: 700px) { .weather-cards { flex-direction: column; align-items: center; gap: 1.5rem; } .weather-card { width: 90vw; min-width: 0; max-width: 400px; } } @media (max-width: 480px) { .weather-card__anim { width: 98vw; max-width: 98vw; height: 110px; } .weather-card { padding: 1.1rem 0.5rem 1rem 0.5rem; } } /* ====== Toggle Controls ====== */ .weather-toggle { display: flex; gap: 0.7rem; margin: 1.2rem 0 0.5rem 0; justify-content: center; flex-wrap: wrap; } .weather-toggle__btn { background: linear-gradient(90deg, #2e2f4a 60%, #23243a 100%); color: #f3f6fa; border: none; border-radius: 2rem; padding: 0.6rem 1.3rem; font-size: 1rem; font-weight: 500; cursor: pointer; box-shadow: 0 2px 8px #0002; transition: background 0.2s, color 0.2s, box-shadow 0.2s; outline: none; position: relative; } .weather-toggle__btn--active, .weather-toggle__btn:focus { background: linear-gradient(90deg, #4fd1c5 60%, #38b2ac 100%); color: #23243a; box-shadow: 0 4px 16px #4fd1c544; } /* ====== Custom Scrollbar ====== */ ::-webkit-scrollbar { width: 8px; background: #23243a; } ::-webkit-scrollbar-thumb { background: #2e2f4a; border-radius: 4px; } </style> </head> <body> <h1>Weather Animation Card Component</h1> <!-- Toggle Controls --> <div class="weather-toggle" id="weatherToggle"> <button class="weather-toggle__btn weather-toggle__btn--active" data-type="all">All</button> <button class="weather-toggle__btn" data-type="wind">Windy</button> <button class="weather-toggle__btn" data-type="rain">Rainy</button> <button class="weather-toggle__btn" data-type="sun">Sunny</button> <button class="weather-toggle__btn" data-type="snow">Snowy</button> </div> <!-- Weather Cards Container --> <div class="weather-cards" id="weatherCards"> <!-- Wind Card --> <div class="weather-card weather-card--active" data-type="wind"> <div class="weather-card__border"></div> <div class="weather-card__title">Windy</div> <div class="weather-card__anim" id="windAnim"></div> <div class="weather-card__footer">Strong breezes, moving clouds</div> </div> <!-- Rain Card --> <div class="weather-card" data-type="rain"> <div class="weather-card__border"></div> <div class="weather-card__title">Rainy</div> <div class="weather-card__anim" id="rainAnim"></div> <div class="weather-card__footer">Showers, puddles, and splashes</div> </div> <!-- Sun Card --> <div class="weather-card" data-type="sun"> <div class="weather-card__border"></div> <div class="weather-card__title">Sunny</div> <div class="weather-card__anim" id="sunAnim"></div> <div class="weather-card__footer">Bright, warm, and glowing</div> </div> <!-- Snow Card --> <div class="weather-card" data-type="snow"> <div class="weather-card__border"></div> <div class="weather-card__title">Snowy</div> <div class="weather-card__anim" id="snowAnim"></div> <div class="weather-card__footer">Gentle flakes, frosty air</div> </div> </div> <!-- ====== JavaScript Animations & Interactivity ====== --> <script> /** * Weather Animation Card Component * Author: Senior Front-End Developer * Description: Modular, interactive, animated weather cards (Wind, Rain, Sun, Snow) */ // --- Utility: Responsive Canvas Sizing --- function fitCanvasToParent(canvas, width, height) { // Set canvas size to match parent div, with devicePixelRatio for sharpness const dpr = window.devicePixelRatio || 1; canvas.width = width * dpr; canvas.height = height * dpr; canvas.style.width = width + 'px'; canvas.style.height = height + 'px'; const ctx = canvas.getContext('2d'); ctx.setTransform(1, 0, 0, 1, 0, 0); // Reset ctx.scale(dpr, dpr); return ctx; } // --- Weather Animation Modules --- // Each animation exposes: init(container), start(), pause(), resume(), destroy() // ========== WIND ANIMATION ========== const WindAnim = (function() { let canvas, ctx, width, height, running = false, rafId; let clouds = [], windLines = [], grass = []; // Cloud, wind, and grass parameters function createCloud() { return { x: Math.random() * width, y: 30 + Math.random() * 30, speed: 0.3 + Math.random() * 0.25, scale: 0.7 + Math.random() * 0.5, opacity: 0.7 + Math.random() * 0.3 }; } function createWindLine() { return { x: -60, y: 60 + Math.random() * 40, length: 60 + Math.random() * 40, speed: 2.2 + Math.random() * 1.2, opacity: 0.18 + Math.random() * 0.12 }; } function createGrass(i) { return { x: 30 + i * 12, baseY: height - 18, sway: Math.random() * Math.PI * 2, swaySpeed: 0.012 + Math.random() * 0.008, height: 18 + Math.random() * 8, color: '#4fd1c5' }; } function drawCloud(cloud) { ctx.save(); ctx.globalAlpha = cloud.opacity; ctx.translate(cloud.x, cloud.y); ctx.scale(cloud.scale, cloud.scale); ctx.beginPath(); ctx.arc(0, 0, 18, Math.PI * 0.5, Math.PI * 1.5); ctx.arc(18, -8, 14, Math.PI * 1, Math.PI * 1.85); ctx.arc(32, 0, 16, Math.PI * 1.37, Math.PI * 0.37, true); ctx.closePath(); ctx.fillStyle = '#b2f5ea'; ctx.shadowColor = '#4fd1c5'; ctx.shadowBlur = 8; ctx.fill(); ctx.restore(); } function drawWindLine(line) { ctx.save(); ctx.globalAlpha = line.opacity; ctx.strokeStyle = '#4fd1c5'; ctx.lineWidth = 2.2; ctx.beginPath(); ctx.moveTo(line.x, line.y); ctx.bezierCurveTo( line.x + line.length * 0.3, line.y - 8, line.x + line.length * 0.7, line.y + 8, line.x + line.length, line.y ); ctx.stroke(); ctx.restore(); } function drawGrass(blade, t) { ctx.save(); ctx.strokeStyle = blade.color; ctx.lineWidth = 2.1; ctx.lineCap = 'round'; ctx.beginPath(); ctx.moveTo(blade.x, blade.baseY); // Sway with wind const sway = Math.sin(t * blade.swaySpeed + blade.sway) * 8; ctx.quadraticCurveTo( blade.x + sway, blade.baseY - blade.height * 0.5, blade.x, blade.baseY - blade.height ); ctx.stroke(); ctx.restore(); } function drawGround() { ctx.save(); ctx.beginPath(); ctx.moveTo(0, height - 10); ctx.quadraticCurveTo(width * 0.5, height, width, height - 10); ctx.lineTo(width, height); ctx.lineTo(0, height); ctx.closePath(); ctx.fillStyle = '#234e52'; ctx.globalAlpha = 0.7; ctx.fill(); ctx.restore(); } function animate(t) { if (!running) return; ctx.clearRect(0, 0, width, height); // Draw clouds clouds.forEach(drawCloud); // Draw wind lines windLines.forEach(drawWindLine); // Draw ground drawGround(); // Draw grass grass.forEach(g => drawGrass(g, t)); // Animate clouds clouds.forEach(cloud => { cloud.x += cloud.speed; if (cloud.x > width + 40) { Object.assign(cloud, createCloud()); cloud.x = -40; } }); // Animate wind lines windLines.forEach(line => { line.x += line.speed; if (line.x > width + 40) { Object.assign(line, createWindLine()); line.x = -60; } }); // Animate grass // (handled in drawGrass) rafId = requestAnimationFrame(animate); } return { init(container) { // Create and fit canvas width = container.offsetWidth; height = container.offsetHeight; canvas = document.createElement('canvas'); ctx = fitCanvasToParent(canvas, width, height); container.appendChild(canvas); // Create clouds, wind lines, grass clouds = Array.from({length: 3}, createCloud); windLines = Array.from({length: 3}, createWindLine); grass = Array.from({length: 10}, (_, i) => createGrass(i)); }, start() { running = true; animate(performance.now()); }, pause() { running = false; cancelAnimationFrame(rafId); }, resume() { if (!running) { running = true; animate(performance.now()); } }, destroy() { this.pause(); if (canvas && canvas.parentNode) canvas.parentNode.removeChild(canvas); } }; })(); // ========== RAIN ANIMATION ========== const RainAnim = (function() { let canvas, ctx, width, height, running = false, rafId; let drops = [], puddle = 0, splashes = []; function createDrop() { return { x: Math.random() * width, y: -10 - Math.random() * 40, speed: 3.5 + Math.random() * 2.5, length: 12 + Math.random() * 8, opacity: 0.5 + Math.random() * 0.4 }; } function createSplash(x, y) { return { x, y, radius: 0, maxRadius: 7 + Math.random() * 4, alpha: 0.7, speed: 0.7 + Math.random() * 0.4 }; } function drawDrop(drop) { ctx.save(); ctx.globalAlpha = drop.opacity; ctx.strokeStyle = '#63b3ed'; ctx.lineWidth = 1.5; ctx.beginPath(); ctx.moveTo(drop.x, drop.y); ctx.lineTo(drop.x, drop.y + drop.length); ctx.stroke(); ctx.restore(); } function drawSplash(splash) { ctx.save(); ctx.globalAlpha = splash.alpha; ctx.strokeStyle = '#90cdf4'; ctx.lineWidth = 1.2; ctx.beginPath(); ctx.arc(splash.x, splash.y, splash.radius, 0, Math.PI, true); ctx.stroke(); ctx.restore(); } function drawPuddle() { ctx.save(); ctx.globalAlpha = 0.18 + Math.min(puddle / 60, 0.22); ctx.beginPath(); ctx.ellipse(width * 0.5, height - 12, 60, 10 + puddle, 0, 0, 2 * Math.PI); ctx.fillStyle = '#63b3ed'; ctx.shadowColor = '#63b3ed'; ctx.shadowBlur = 8; ctx.fill(); ctx.restore(); } function animate() { if (!running) return; ctx.clearRect(0, 0, width, height); // Draw puddle drawPuddle(); // Draw drops drops.forEach(drawDrop); // Draw splashes splashes.forEach(drawSplash); // Animate drops drops.forEach(drop => { drop.y += drop.speed; if (drop.y > height - 18) { // Splash splashes.push(createSplash(drop.x, height - 18)); puddle = Math.min(puddle + 0.12, 18); Object.assign(drop, createDrop()); drop.x = Math.random() * width; drop.y = -10 - Math.random() * 40; } }); // Animate splashes splashes = splashes.filter(splash => { splash.radius += splash.speed; splash.alpha -= 0.04; return splash.alpha > 0.05; }); rafId = requestAnimationFrame(animate); } return { init(container) { width = container.offsetWidth; height = container.offsetHeight; canvas = document.createElement('canvas'); ctx = fitCanvasToParent(canvas, width, height); container.appendChild(canvas); drops = Array.from({length: 18}, createDrop); puddle = 0; splashes = []; }, start() { running = true; animate(); }, pause() { running = false; cancelAnimationFrame(rafId); }, resume() { if (!running) { running = true; animate(); } }, destroy() { this.pause(); if (canvas && canvas.parentNode) canvas.parentNode.removeChild(canvas); } }; })(); // ========== SUN ANIMATION ========== const SunAnim = (function() { let svg, rays = [], sun, running = false, rafId, t = 0; function createSVG(width, height) { // SVG for crisp, scalable sun/rays const ns = 'http://www.w3.org/2000/svg'; svg = document.createElementNS(ns, 'svg'); svg.setAttribute('width', width); svg.setAttribute('height', height); svg.style.display = 'block'; svg.style.overflow = 'visible'; svg.style.width = width + 'px'; svg.style.height = height + 'px'; return svg; } function createSunAndRays(width, height) { // Sun sun = document.createElementNS(svg.namespaceURI, 'circle'); sun.setAttribute('cx', width / 2); sun.setAttribute('cy', height / 2 + 10); sun.setAttribute('r', 32); sun.setAttribute('fill', 'url(#sunGradient)'); sun.setAttribute('filter', 'url(#sunGlow)'); svg.appendChild(sun); // Rays rays = []; for (let i = 0; i < 12; i++) { const ray = document.createElementNS(svg.namespaceURI, 'rect'); ray.setAttribute('x', width / 2 - 3); ray.setAttribute('y', height / 2 - 60); ray.setAttribute('width', 6); ray.setAttribute('height', 28); ray.setAttribute('rx', 3); ray.setAttribute('fill', '#f6e05e'); ray.setAttribute('opacity', '0.7'); ray.setAttribute('transform', `rotate(${i * 30} ${width / 2} ${height / 2 + 10})`); svg.appendChild(ray); rays.push(ray); } } function createDefs(width, height) { // Sun radial gradient const defs = document.createElementNS(svg.namespaceURI, 'defs'); const grad = document.createElementNS(svg.namespaceURI, 'radialGradient'); grad.setAttribute('id', 'sunGradient'); grad.setAttribute('cx', '50%'); grad.setAttribute('cy', '50%'); grad.setAttribute('r', '60%'); grad.innerHTML = ` <stop offset="0%" stop-color="#fffde4"/> <stop offset="60%" stop-color="#f6e05e"/> <stop offset="100%" stop-color="#ecc94b"/> `; defs.appendChild(grad); // Sun glow filter const filter = document.createElementNS(svg.namespaceURI, 'filter'); filter.setAttribute('id', 'sunGlow'); filter.innerHTML = ` <feGaussianBlur stdDeviation="6" result="glow"/> <feMerge> <feMergeNode in="glow"/> <feMergeNode in="SourceGraphic"/> </feMerge> `; defs.appendChild(filter); svg.appendChild(defs); } function animate() { if (!running) return; t += 0.016; // Animate rays: rotate, pulse opacity rays.forEach((ray, i) => { const angle = i * 30 + t * 18; const pulse = 0.6 + 0.4 * Math.abs(Math.sin(t + i)); ray.setAttribute('opacity', pulse.toFixed(2)); ray.setAttribute('transform', `rotate(${angle} 90 80)`); }); // Animate sun: pulse radius and glow const r = 32 + Math.sin(t * 1.2) * 2.5; sun.setAttribute('r', r); sun.setAttribute('fill', 'url(#sunGradient)'); rafId = requestAnimationFrame(animate); } return { init(container) { const width = container.offsetWidth, height = container.offsetHeight; svg = createSVG(width, height); createDefs(width, height); createSunAndRays(width, height); container.appendChild(svg); }, start() { running = true; animate(); }, pause() { running = false; cancelAnimationFrame(rafId); }, resume() { if (!running) { running = true; animate(); } }, destroy() { this.pause(); if (svg && svg.parentNode) svg.parentNode.removeChild(svg); } }; })(); // ========== SNOW ANIMATION ========== const SnowAnim = (function() { let canvas, ctx, width, height, running = false, rafId; let flakes = [], ground = [], frost = 0; function createFlake() { return { x: Math.random() * width, y: -10 - Math.random() * 40, r: 2.5 + Math.random() * 2.5, speed: 0.7 + Math.random() * 0.7, drift: (Math.random() - 0.5) * 0.7, opacity: 0.5 + Math.random() * 0.5 }; } function drawFlake(flake) { ctx.save(); ctx.globalAlpha = flake.opacity; ctx.beginPath(); ctx.arc(flake.x, flake.y, flake.r, 0, 2 * Math.PI); ctx.fillStyle = '#e6f6ff'; ctx.shadowColor = '#bee3f8'; ctx.shadowBlur = 8; ctx.fill(); ctx.restore(); } function drawGround() { ctx.save(); ctx.globalAlpha = 0.7; ctx.beginPath(); ctx.moveTo(0, height - 10); ctx.quadraticCurveTo(width * 0.5, height - 2 - frost, width, height - 10); ctx.lineTo(width, height); ctx.lineTo(0, height); ctx.closePath(); ctx.fillStyle = '#bee3f8'; ctx.shadowColor = '#e6f6ff'; ctx.shadowBlur = 8; ctx.fill(); ctx.restore(); } function drawFrost() { ctx.save(); ctx.globalAlpha = 0.13 + Math.min(frost / 30, 0.12); ctx.beginPath(); ctx.ellipse(width * 0.5, height - 18, 60, 10 + frost, 0, 0, 2 * Math.PI); ctx.fillStyle = '#e6f6ff'; ctx.fill(); ctx.restore(); } function animate() { if (!running) return; ctx.clearRect(0, 0, width, height); // Draw frost drawFrost(); // Draw flakes flakes.forEach(drawFlake); // Draw ground drawGround(); // Animate flakes flakes.forEach(flake => { flake.x += flake.drift + Math.sin(flake.y * 0.03) * 0.5; flake.y += flake.speed; if (flake.y > height - 14 - frost) { frost = Math.min(frost + 0.04, 18); Object.assign(flake, createFlake()); flake.y = -10 - Math.random() * 40; } }); rafId = requestAnimationFrame(animate); } return { init(container) { width = container.offsetWidth; height = container.offsetHeight; canvas = document.createElement('canvas'); ctx = fitCanvasToParent(canvas, width, height); container.appendChild(canvas); flakes = Array.from({length: 18}, createFlake); frost = 0; }, start() { running = true; animate(); }, pause() { running = false; cancelAnimationFrame(rafId); }, resume() { if (!running) { running = true; animate(); } }, destroy() { this.pause(); if (canvas && canvas.parentNode) canvas.parentNode.removeChild(canvas); } }; })(); // ========== Weather Card Controller ========== // Map weather type to animation module and DOM const weatherTypes = ['wind', 'rain', 'sun', 'snow']; const animModules = { wind: WindAnim, rain: RainAnim, sun: SunAnim, snow: SnowAnim }; const animContainers = { wind: document.getElementById('windAnim'), rain: document.getElementById('rainAnim'), sun: document.getElementById('sunAnim'), snow: document.getElementById('snowAnim') }; const animInstances = {}; // Initialize all animations (but only start if visible) function initAllAnims() { weatherTypes.forEach(type => { animModules[type].init(animContainers[type]); }); } function startAnim(type) { animModules[type].start(); } function pauseAnim(type) { animModules[type].pause(); } function resumeAnim(type) { animModules[type].resume(); } function destroyAnim(type) { animModules[type].destroy(); } // --- View State Management --- let currentView = 'all'; // 'all' or weather type function switchWeather(type) { // Pause all anims weatherTypes.forEach(pauseAnim); // Remove active class from all cards document.querySelectorAll('.weather-card').forEach(card => { card.classList.remove('weather-card--active'); }); // Remove active from all toggle buttons document.querySelectorAll('.weather-toggle__btn').forEach(btn => { btn.classList.remove('weather-toggle__btn--active'); }); // Set active toggle button const btn = document.querySelector(`.weather-toggle__btn[data-type="${type}"]`); if (btn) btn.classList.add('weather-toggle__btn--active'); // Set view const cardsContainer = document.getElementById('weatherCards'); if (type === 'all') { // Show all cards cardsContainer.classList.remove('weather-cards--single'); document.querySelectorAll('.weather-card').forEach(card => { card.style.display = ''; }); // Start all anims weatherTypes.forEach(resumeAnim); // Set all cards as active document.querySelectorAll('.weather-card').forEach(card => { card.classList.add('weather-card--active'); }); } else { // Show only selected card cardsContainer.classList.add('weather-cards--single'); document.querySelectorAll('.weather-card').forEach(card => { if (card.getAttribute('data-type') === type) { card.style.display = ''; card.classList.add('weather-card--active'); } else { card.style.display = 'none'; } }); // Start only selected anim resumeAnim(type); } currentView = type; } // --- Toggle Button Event Listeners --- document.getElementById('weatherToggle').addEventListener('click', function(e) { if (e.target.classList.contains('weather-toggle__btn')) { const type = e.target.getAttribute('data-type'); switchWeather(type); } }); // --- Responsive: Re-initialize canvases/SVGs on resize --- let resizeTimeout; window.addEventListener('resize', function() { clearTimeout(resizeTimeout); resizeTimeout = setTimeout(() => { // Destroy and re-init all anims weatherTypes.forEach(type => { destroyAnim(type); animModules[type].init(animContainers[type]); }); // Resume anims as per current view if (currentView === 'all') { weatherTypes.forEach(resumeAnim); } else { resumeAnim(currentView); } }, 300); }); // --- Initialize on DOMContentLoaded --- document.addEventListener('DOMContentLoaded', function() { initAllAnims(); // Start all anims by default weatherTypes.forEach(startAnim); // Set initial view switchWeather('all'); }); // --- Expose switchWeather globally for programmatic use --- window.switchWeather = switchWeather; </script> </body> </html>
Key Features:
- Dark, modern theme with subtle gradients and noise.
- Responsive layout: Cards stack vertically on small screens.
- Distinct, smooth animations for Wind (clouds, wind lines, grass), Rain (raindrops, splashes, puddle), Sun (SVG rays, glowing sun), and Snow (flakes, frost, snow accumulation).
- Interactive toggle: Switch between all cards or a single card view. Animations pause/resume as needed.
- Reusable
switchWeather(type)function for programmatic control. - Clean, modular code with thorough comments and BEM-style class naming.
- No external dependencies; all code is inline and production-ready.
Try it out!
Open the file in your browser, resize the window, and toggle between weather types for a delightful, immersive UI/UX experience.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.