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" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Animated Weather Cards</title> <style> /* =============== BASIC LAYOUT =============== */ *{box-sizing:border-box;padding:0;margin:0} body{ background:#121212; color:#fff; font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,sans-serif; min-height:100vh; display:flex; flex-direction:column; align-items:center; padding:25px 10px; } /* -------- Buttons to switch conditions -------- */ .buttons{ margin-bottom:25px; } .buttons button{ border:none; outline:none; background:#1E88E5; color:#fff; padding:8px 18px; margin:0 4px; border-radius:6px; cursor:pointer; transition:all .25s; } .buttons button:hover{background:#1565C0} .buttons button.active{ background:#FFC107; color:#000; } /* ---------- Weather‑card container ------------ */ .container{ display:flex; flex-wrap:wrap; gap:22px; justify-content:center; width:100%; } .weather-card{ width:250px; height:320px; background:#1c1c1c; border-radius:18px; padding:20px; position:relative; overflow:hidden; transition:transform .35s; } .weather-card:hover{transform:translateY(-6px)} .weather-card.hide{display:none} .weather-card .icon{ position:relative; height:130px; margin-bottom:22px; } .weather-card h3{font-weight:600;margin-bottom:6px;font-size:1.25rem;} .weather-card p{font-size:.9rem;opacity:.85;} /* =============== SHARED ARTWORK =============== */ /* --- cloud for rain & wind --- */ .cloud{ width:90px;height:50px; background:#fafafa; border-radius:50px; position:absolute; top:28px;left:50%; transform:translateX(-50%); } .cloud:before,.cloud:after{ content:''; position:absolute; background:#fafafa; border-radius:50%; } .cloud:before{width:60px;height:60px;top:-20px;left:-4px;} .cloud:after{width:60px;height:60px;top:-14px;right:-10px;} /* =============== WIND =============== */ .wind-line{ position:absolute; height:3px; background:#fff; border-radius:2px; opacity:.8; animation:blow 3s linear infinite; } .wind-line.line1{width:110px;top:15px;animation-delay:0s} .wind-line.line2{width:90px;top:40px;animation-delay:.8s} .wind-line.line3{width:70px;top:65px;animation-delay:1.6s} @keyframes blow{ 0% {transform:translateX(-130%);} 100%{transform:translateX(130%);} } /* =============== RAIN =============== */ .raindrops{ position:absolute; inset:0; overflow:hidden;} .drop{ position:absolute; bottom:100%; width:2px; height:12px; background:#4FC3F7; border-radius:1px; animation:fall 1s linear infinite; } @keyframes fall{ 0%{transform:translateY(0)} 100%{transform:translateY(220px)} } /* =============== SUN =============== */ .sun-core{ width:70px;height:70px; background:#FFEB3B; border-radius:50%; position:absolute; top:20px;left:50%; transform:translateX(-50%); box-shadow:0 0 18px 4px #FFEB3B; animation:pulse 3s ease-in-out infinite; } @keyframes pulse{ 0%,100%{box-shadow:0 0 12px 2px #FFEB3B} 50% {box-shadow:0 0 25px 6px #FFEB3B} } /* rotating rays */ .sun-rays{ position:absolute; width:120px;height:120px; top:-15px;left:50%; transform:translateX(-50%); animation:spin 15s linear infinite; } .ray{ position:absolute; width:8px;height:30px; background:#FFEB3B; border-radius:4px; top:0;left:50%; transform-origin:bottom center; } .ray:nth-child(1){transform:translateX(-50%) rotate(0deg);} .ray:nth-child(2){transform:translateX(-50%) rotate(45deg);} .ray:nth-child(3){transform:translateX(-50%) rotate(90deg);} .ray:nth-child(4){transform:translateX(-50%) rotate(135deg);} .ray:nth-child(5){transform:translateX(-50%) rotate(180deg);} .ray:nth-child(6){transform:translateX(-50%) rotate(225deg);} .ray:nth-child(7){transform:translateX(-50%) rotate(270deg);} .ray:nth-child(8){transform:translateX(-50%) rotate(315deg);} @keyframes spin{from{transform:translateX(-50%) rotate(0deg);}to{transform:translateX(-50%) rotate(360deg);}} /* =============== SNOW =============== */ .snow-container{position:absolute;inset:0;overflow:hidden;} .snowflake{ position:absolute; width:7px;height:7px; background:#fff; border-radius:50%; opacity:.8; top:-10px; animation:snow 5s linear infinite; } @keyframes snow{ 0% {transform:translateY(0) scale(1)} 100%{transform:translateY(220px) scale(1.2)} } </style> </head> <body> <!-- Buttons to show one / all cards --> <div class="buttons"> <button data-target="all" class="active">All</button> <button data-target="sun" >Sun</button> <button data-target="rain" >Rain</button> <button data-target="wind" >Wind</button> <button data-target="snow" >Snow</button> </div> <!-- Weather cards --> <div class="container"> <!-- WIND --> <div class="weather-card wind" data-condition="wind"> <div class="icon"> <div class="cloud"></div> <div class="wind-line line1"></div> <div class="wind-line line2"></div> <div class="wind-line line3"></div> </div> <h3>Windy</h3> <p>Temperature: 18 °C</p> <p>Wind: 35 km/h SW</p> <p>Humidity: 55 %</p> </div> <!-- RAIN --> <div class="weather-card rain" data-condition="rain"> <div class="icon"> <div class="cloud"></div> <div class="raindrops"></div> </div> <h3>Rainy</h3> <p>Temperature: 16 °C</p> <p>Rain: 8 mm / hr</p> <p>Humidity: 92 %</p> </div> <!-- SUN --> <div class="weather-card sun" data-condition="sun"> <div class="icon"> <div class="sun-rays"> <div class="ray"></div><div class="ray"></div><div class="ray"></div><div class="ray"></div> <div class="ray"></div><div class="ray"></div><div class="ray"></div><div class="ray"></div> </div> <div class="sun-core"></div> </div> <h3>Sunny</h3> <p>Temperature: 27 °C</p> <p>UV Index: High</p> <p>Humidity: 38 %</p> </div> <!-- SNOW --> <div class="weather-card snow" data-condition="snow"> <div class="icon"> <div class="snow-container"></div> </div> <h3>Snowy</h3> <p>Temperature: −4 °C</p> <p>Snow: 4 cm</p> <p>Wind: 12 km/h N</p> </div> </div> <script> /* ================================================== Small helper to create repeated drops / flakes ================================================== */ document.addEventListener('DOMContentLoaded',() =>{ /* ---- Rain drops ---- */ const rainCard = document.querySelector('.rain'); const dropsBox = rainCard.querySelector('.raindrops'); for(let i=0;i<30;i++){ const d = document.createElement('span'); d.className='drop'; d.style.left = Math.random()*100 + '%'; d.style.animationDelay = (Math.random()) + 's'; d.style.animationDuration = (.8 + Math.random()*0.6) + 's'; dropsBox.appendChild(d); } /* ---- Snow flakes ---- */ const snowCard = document.querySelector('.snow'); const snowBox = snowCard.querySelector('.snow-container'); for(let i=0;i<25;i++){ const f = document.createElement('span'); f.className='snowflake'; f.style.left = Math.random()*100 + '%'; f.style.opacity = .6 + Math.random()*0.4; f.style.transform = `scale(${.6+Math.random()*0.8})`; f.style.animationDelay = Math.random()*5 + 's'; f.style.animationDuration = (4+Math.random()*3) + 's'; snowBox.appendChild(f); } /* ---- Switcher buttons ---- */ const buttons = document.querySelectorAll('.buttons button'); const cards = document.querySelectorAll('.weather-card'); buttons.forEach(btn=>{ btn.addEventListener('click',()=>{ // visual state buttons.forEach(b=>b.classList.remove('active')); btn.classList.add('active'); const target = btn.dataset.target; if(target==='all'){ cards.forEach(c=>c.classList.remove('hide')); }else{ cards.forEach(c=>{ c.classList.toggle('hide', c.dataset.condition!==target); }); } }); }); }); </script> </body> </html>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.