你是一位就职于苹果公司的顶级前端工程师。请创建一个包含CSS和JavaScript的HTML文件,用于生成动画天气卡片。卡片需要以不同动画效果直观展示以下天气状况:…
- User
你是一位就职于苹果公司的顶级前端工程师。请创建一个包含CSS和JavaScript的HTML文件,用于生成动画天气卡片。卡片需要以不同动画效果直观展示以下天气状况:
风力(如:飘动的云朵、摇曳的树木或风线)
降雨(如:下落的雨滴、形成的水洼)
晴天(如:闪耀的光线、明亮的背景)
下雪(如:飘落的雪花、积雪效果)
所有天气卡片需要并排显示,背景采用深色设计。所有HTML、CSS和JavaScript代码都需包含在这个单一文件中。JavaScript部分需包含切换不同天气状态的功能(例如通过函数或按钮组),以演示每种天气的动画效果。
将前端显示效果优化得更精致流畅,打造出价值20元/月的精品天气应用既视感。
Assistant
以下是一个包含CSS和JavaScript的HTML文件,用于生成动画天气卡片:
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>动画天气卡片</title> <style> /* 全局样式 */ body { background-color: #2f2f2f; font-family: Arial, sans-serif; margin: 0; padding: 0; } /* 天气卡片容器 */ .weather-cards { display: flex; justify-content: space-around; align-items: center; padding: 20px; } /* 天气卡片 */ .weather-card { position: relative; width: 200px; height: 250px; background-color: #4f4f4f; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); overflow: hidden; } /* 风力动画 */ .wind { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .wind .cloud { position: absolute; top: 20px; left: 20px; width: 50px; height: 20px; background-color: #fff; border-radius: 10px; animation: wind-cloud 5s linear infinite; } .wind .tree { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 20px; height: 50px; background-color: #3e8e41; animation: wind-tree 3s ease-in-out infinite; } @keyframes wind-cloud { 0% { transform: translateX(0); } 100% { transform: translateX(150px); } } @keyframes wind-tree { 0% { transform: translateX(-50%) rotate(0deg); } 50% { transform: translateX(-50%) rotate(10deg); } 100% { transform: translateX(-50%) rotate(0deg); } } /* 降雨动画 */ .rain { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .rain .drop { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); width: 5px; height: 10px; background-color: #87ceeb; border-radius: 50%; animation: rain-drop 2s linear infinite; } .rain .puddle { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 50px; height: 10px; background-color: #87ceeb; border-radius: 50%; animation: rain-puddle 5s ease-in-out infinite; } @keyframes rain-drop { 0% { transform: translateX(-50%) translateY(0); } 100% { transform: translateX(-50%) translateY(250px); } } @keyframes rain-puddle { 0% { transform: translateX(-50%) scale(0); } 100% { transform: translateX(-50%) scale(1); } } /* 晴天动画 */ .sunny { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #ffff00; opacity: 0.5; } .sunny .sun { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 50px; height: 50px; background-color: #ffff00; border-radius: 50%; box-shadow: 0 0 10px #ffff00; animation: sunny-sun 5s ease-in-out infinite; } @keyframes sunny-sun { 0% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.2); } 100% { transform: translate(-50%, -50%) scale(1); } } /* 下雪动画 */ .snow { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .snow .flake { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); width: 10px; height: 10px; background-color: #fff; border-radius: 50%; animation: snow-flake 5s linear infinite; } .snow .ground { position: absolute; bottom: 0; left: 0; width: 100%; height: 20px; background-color: #fff; animation: snow-ground 5s ease-in-out infinite; } @keyframes snow-flake { 0% { transform: translateX(-50%) translateY(0); } 100% { transform: translateX(-50%) translateY(250px); } } @keyframes snow-ground { 0% { height: 0; } 100% { height: 50px; } } /* 按钮组 */ .button-group { text-align: center; margin-top: 20px; } .button-group button { margin: 0 10px; padding: 10px 20px; border: none; border-radius: 5px; background-color: #4f4f4f; color: #fff; cursor: pointer; } .button-group button:hover { background-color: #3e8e41; } </style> </head> <body> <div class="weather-cards"> <div class="weather-card" id="wind-card"> <div class="wind"> <div class="cloud"></div> <div class="tree"></div> </div> </div> <div class="weather-card" id="rain-card"> <div class="rain"> <div class="drop"></div> <div class="puddle"></div> </div> </div> <div class="weather-card" id="sunny-card"> <div class="sunny"> <div class="sun"></div> </div> </div> <div class="weather-card" id="snow-card"> <div class="snow"> <div class="flake"></div> <div class="ground"></div> </div> </div> </div> <div class="button-group"> <button onclick="showWind()">风力</button> <button onclick="showRain()">降雨</button> <button onclick="showSunny()">晴天</button> <button onclick="showSnow()">下雪</button> </div> <script> // 获取天气卡片元素 const windCard = document.getElementById('wind-card'); const rainCard = document.getElementById('rain-card'); const sunnyCard = document.getElementById('sunny-card'); const snowCard = document.getElementById('snow-card'); // 定义显示天气的函数 function showWind() { windCard.style.display = 'block'; rainCard.style.display = 'none'; sunnyCard.style.display = 'none'; snowCard.style.display = 'none'; } function showRain() { windCard.style.display = 'none'; rainCard.style.display = 'block'; sunnyCard.style.display = 'none'; snowCard.style.display = 'none'; } function showSunny() { windCard.style.display = 'none'; rainCard.style.display = 'none'; sunnyCard.style.display = 'block'; snowCard.style.display = 'none'; } function showSnow() { windCard.style.display = 'none'; rainCard.style.display = 'none'; sunnyCard.style.display = 'none'; snowCard.style.display = 'block'; } // 初始化显示晴天 showSunny(); </script> </body> </html>这个HTML文件包含四个天气卡片,分别代表风力、降雨、晴天和下雪。每个卡片都有其独特的动画效果。JavaScript部分定义了四个函数,用于切换不同天气状态的显示。通过点击按钮组中的按钮,可以切换显示不同的天气卡片。初始状态下,晴天卡片被显示。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.