690 lines
23 KiB
HTML
690 lines
23 KiB
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>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
:root {
|
|
--sunny-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
|
|
--sunny-accent: #ffd93d;
|
|
--rainy-bg: linear-gradient(135deg, #1a1a2e 0%, #2d3436 50%, #636e72 100%);
|
|
--rainy-accent: #74b9ff;
|
|
--snowy-bg: linear-gradient(135deg, #1a1a2e 0%, #2c3e50 50%, #7f8c8d 100%);
|
|
--snowy-accent: #dfe6e9;
|
|
--windy-bg: linear-gradient(135deg, #1a1a2e 0%, #2d3436 50%, #00cec9 100%);
|
|
--windy-accent: #81ecec;
|
|
--card-bg: rgba(255, 255, 255, 0.08);
|
|
--card-border: rgba(255, 255, 255, 0.12);
|
|
--text-primary: #ffffff;
|
|
--text-secondary: rgba(255, 255, 255, 0.6);
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
|
|
min-height: 100vh;
|
|
overflow: hidden;
|
|
background: var(--sunny-bg);
|
|
transition: background 0.8s ease;
|
|
}
|
|
|
|
body[data-weather="sunny"] {
|
|
background: var(--sunny-bg);
|
|
}
|
|
|
|
body[data-weather="rainy"] {
|
|
background: var(--rainy-bg);
|
|
}
|
|
|
|
body[data-weather="snowy"] {
|
|
background: var(--snowy-bg);
|
|
}
|
|
|
|
body[data-weather="windy"] {
|
|
background: var(--windy-bg);
|
|
}
|
|
|
|
/* 动画画布 */
|
|
.weather-canvas {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
z-index: 0;
|
|
pointer-events: none;
|
|
}
|
|
|
|
/* 主卡片容器 */
|
|
.card-container {
|
|
position: relative;
|
|
z-index: 1;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
/* 天气卡片 */
|
|
.weather-card {
|
|
width: 100%;
|
|
max-width: 420px;
|
|
background: var(--card-bg);
|
|
backdrop-filter: blur(40px);
|
|
-webkit-backdrop-filter: blur(40px);
|
|
border-radius: 32px;
|
|
border: 1px solid var(--card-border);
|
|
box-shadow:
|
|
0 25px 50px rgba(0, 0, 0, 0.4),
|
|
0 0 0 1px rgba(255, 255, 255, 0.05),
|
|
inset 0 1px 0 rgba(255, 255, 255, 0.1);
|
|
padding: 40px 32px;
|
|
transition: all 0.5s ease;
|
|
position: relative;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.weather-card::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: -50%;
|
|
left: -50%;
|
|
width: 200%;
|
|
height: 200%;
|
|
background: radial-gradient(circle, rgba(255,255,255,0.08) 0%, transparent 70%);
|
|
pointer-events: none;
|
|
}
|
|
|
|
/* 城市名称 */
|
|
.city {
|
|
text-align: center;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.city-name {
|
|
font-size: 28px;
|
|
font-weight: 600;
|
|
color: var(--text-primary);
|
|
letter-spacing: 2px;
|
|
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
.weather-desc {
|
|
text-align: center;
|
|
font-size: 14px;
|
|
color: var(--text-secondary);
|
|
margin-bottom: 30px;
|
|
letter-spacing: 1px;
|
|
}
|
|
|
|
/* 温度显示 */
|
|
.temp-container {
|
|
text-align: center;
|
|
margin-bottom: 40px;
|
|
}
|
|
|
|
.temperature {
|
|
font-size: 96px;
|
|
font-weight: 200;
|
|
color: var(--text-primary);
|
|
line-height: 1;
|
|
text-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.temp-unit {
|
|
font-size: 36px;
|
|
vertical-align: super;
|
|
opacity: 0.8;
|
|
}
|
|
|
|
/* 控制按钮 */
|
|
.controls {
|
|
display: flex;
|
|
justify-content: center;
|
|
gap: 12px;
|
|
margin-bottom: 30px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.weather-btn {
|
|
width: 56px;
|
|
height: 56px;
|
|
border-radius: 16px;
|
|
border: 1px solid var(--card-border);
|
|
background: rgba(255, 255, 255, 0.05);
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
position: relative;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.weather-btn::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 100%);
|
|
opacity: 0;
|
|
transition: opacity 0.3s ease;
|
|
}
|
|
|
|
.weather-btn:hover::before {
|
|
opacity: 1;
|
|
}
|
|
|
|
.weather-btn:hover {
|
|
transform: translateY(-3px);
|
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
|
|
border-color: rgba(255, 255, 255, 0.25);
|
|
}
|
|
|
|
.weather-btn.active {
|
|
background: rgba(255, 255, 255, 0.15);
|
|
border-color: rgba(255, 255, 255, 0.3);
|
|
box-shadow: 0 0 30px rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.weather-btn svg {
|
|
width: 24px;
|
|
height: 24px;
|
|
stroke: var(--text-secondary);
|
|
transition: stroke 0.3s ease;
|
|
}
|
|
|
|
.weather-btn:hover svg,
|
|
.weather-btn.active svg {
|
|
stroke: var(--text-primary);
|
|
}
|
|
|
|
/* 天气详情 */
|
|
.details {
|
|
display: grid;
|
|
grid-template-columns: repeat(3, 1fr);
|
|
gap: 16px;
|
|
}
|
|
|
|
.detail-item {
|
|
background: rgba(255, 255, 255, 0.05);
|
|
border-radius: 16px;
|
|
padding: 16px;
|
|
text-align: center;
|
|
border: 1px solid var(--card-border);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.detail-item:hover {
|
|
background: rgba(255, 255, 255, 0.08);
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.detail-icon {
|
|
width: 24px;
|
|
height: 24px;
|
|
margin: 0 auto 8px;
|
|
stroke: var(--text-secondary);
|
|
}
|
|
|
|
.detail-value {
|
|
font-size: 18px;
|
|
font-weight: 500;
|
|
color: var(--text-primary);
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.detail-label {
|
|
font-size: 11px;
|
|
color: var(--text-secondary);
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
}
|
|
|
|
/* 动画元素样式 */
|
|
.sun {
|
|
position: absolute;
|
|
width: 120px;
|
|
height: 120px;
|
|
background: radial-gradient(circle, #ffd93d 0%, #ff9f43 50%, transparent 70%);
|
|
border-radius: 50%;
|
|
top: -30px;
|
|
right: -30px;
|
|
box-shadow: 0 0 80px rgba(255, 217, 61, 0.6),
|
|
0 0 160px rgba(255, 217, 61, 0.4);
|
|
animation: sunPulse 4s ease-in-out infinite;
|
|
}
|
|
|
|
@keyframes sunPulse {
|
|
0%, 100% { transform: scale(1); opacity: 1; }
|
|
50% { transform: scale(1.1); opacity: 0.9; }
|
|
}
|
|
|
|
.sun-ray {
|
|
position: absolute;
|
|
width: 200%;
|
|
height: 200%;
|
|
top: -50%;
|
|
left: -50%;
|
|
background: conic-gradient(from 0deg, transparent 0deg, rgba(255, 217, 61, 0.1) 10deg, transparent 20deg);
|
|
animation: sunRotate 30s linear infinite;
|
|
}
|
|
|
|
@keyframes sunRotate {
|
|
from { transform: rotate(0deg); }
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
|
|
.cloud {
|
|
position: absolute;
|
|
background: rgba(255, 255, 255, 0.15);
|
|
border-radius: 50px;
|
|
animation: cloudFloat 8s ease-in-out infinite;
|
|
}
|
|
|
|
.cloud::before,
|
|
.cloud::after {
|
|
content: '';
|
|
position: absolute;
|
|
background: rgba(255, 255, 255, 0.15);
|
|
border-radius: 50%;
|
|
}
|
|
|
|
@keyframes cloudFloat {
|
|
0%, 100% { transform: translateX(0); }
|
|
50% { transform: translateX(20px); }
|
|
}
|
|
|
|
.rain-drop {
|
|
position: absolute;
|
|
width: 2px;
|
|
height: 20px;
|
|
background: linear-gradient(to bottom, transparent, rgba(116, 185, 255, 0.8));
|
|
border-radius: 2px;
|
|
animation: rainFall linear infinite;
|
|
}
|
|
|
|
@keyframes rainFall {
|
|
0% { transform: translateY(-100vh); opacity: 0; }
|
|
10% { opacity: 1; }
|
|
90% { opacity: 1; }
|
|
100% { transform: translateY(100vh); opacity: 0; }
|
|
}
|
|
|
|
.snowflake {
|
|
position: absolute;
|
|
width: 8px;
|
|
height: 8px;
|
|
background: rgba(223, 230, 233, 0.9);
|
|
border-radius: 50%;
|
|
filter: blur(1px);
|
|
animation: snowFall linear infinite;
|
|
box-shadow: 0 0 10px rgba(223, 230, 233, 0.5);
|
|
}
|
|
|
|
@keyframes snowFall {
|
|
0% { transform: translateY(-100vh) rotate(0deg); opacity: 0; }
|
|
10% { opacity: 1; }
|
|
90% { opacity: 1; }
|
|
100% { transform: translateY(100vh) rotate(360deg); opacity: 0; }
|
|
}
|
|
|
|
.leaf {
|
|
position: absolute;
|
|
width: 20px;
|
|
height: 20px;
|
|
background: linear-gradient(135deg, #81ecec 0%, #00cec9 100%);
|
|
clip-path: polygon(0% 0%, 100% 50%, 0% 100%, 20% 50%);
|
|
animation: leafBlow linear infinite;
|
|
opacity: 0.7;
|
|
}
|
|
|
|
@keyframes leafBlow {
|
|
0% {
|
|
transform: translateX(-50px) rotate(0deg) translateY(0);
|
|
opacity: 0;
|
|
}
|
|
10% { opacity: 0.7; }
|
|
90% { opacity: 0.7; }
|
|
100% {
|
|
transform: translateX(calc(100vw + 50px)) rotate(720deg) translateY(100px);
|
|
opacity: 0;
|
|
}
|
|
}
|
|
|
|
/* 闪电效果 */
|
|
.lightning {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background: rgba(255, 255, 255, 0.1);
|
|
opacity: 0;
|
|
pointer-events: none;
|
|
animation: lightning 4s ease-in-out infinite;
|
|
}
|
|
|
|
@keyframes lightning {
|
|
0%, 90%, 100% { opacity: 0; }
|
|
92%, 94%, 96% { opacity: 0.3; }
|
|
}
|
|
|
|
/* 响应式 */
|
|
@media (max-width: 480px) {
|
|
.weather-card {
|
|
padding: 30px 24px;
|
|
border-radius: 24px;
|
|
}
|
|
|
|
.temperature {
|
|
font-size: 72px;
|
|
}
|
|
|
|
.weather-btn {
|
|
width: 48px;
|
|
height: 48px;
|
|
}
|
|
|
|
.details {
|
|
grid-template-columns: repeat(3, 1fr);
|
|
gap: 10px;
|
|
}
|
|
|
|
.detail-item {
|
|
padding: 12px 8px;
|
|
}
|
|
|
|
.detail-value {
|
|
font-size: 14px;
|
|
}
|
|
|
|
.detail-label {
|
|
font-size: 9px;
|
|
}
|
|
}
|
|
|
|
/* 过渡动画 */
|
|
.fade-transition {
|
|
animation: fadeIn 0.5s ease;
|
|
}
|
|
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; transform: scale(0.95); }
|
|
to { opacity: 1; transform: scale(1); }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body data-weather="sunny">
|
|
<!-- 动画画布 -->
|
|
<canvas class="weather-canvas" id="weatherCanvas"></canvas>
|
|
|
|
<!-- 主容器 -->
|
|
<div class="card-container">
|
|
<!-- 天气卡片 -->
|
|
<div class="weather-card">
|
|
<div class="sun" id="sunElement">
|
|
<div class="sun-ray"></div>
|
|
</div>
|
|
|
|
<!-- 城市 -->
|
|
<div class="city">
|
|
<div class="city-name" id="cityName">上海市</div>
|
|
</div>
|
|
|
|
<!-- 天气描述 -->
|
|
<div class="weather-desc" id="weatherDesc">晴朗</div>
|
|
|
|
<!-- 温度 -->
|
|
<div class="temp-container">
|
|
<div class="temperature" id="temperature">25<span class="temp-unit">°</span></div>
|
|
</div>
|
|
|
|
<!-- 控制按钮 -->
|
|
<div class="controls">
|
|
<button class="weather-btn active" data-weather="sunny" title="晴天">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<circle cx="12" cy="12" r="5"/>
|
|
<path d="M12 1v2m0 18v2M4.22 4.22l1.42 1.42m12.72 12.72 1.42 1.42M1 12h2m18 0h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/>
|
|
</svg>
|
|
</button>
|
|
<button class="weather-btn" data-weather="rainy" title="雨天">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M16 13v8m-8 0v8m-4 0v8m4-16v8m-4 0v8"/>
|
|
<path d="M12 2v2m0 16v2"/>
|
|
<path d="M20 12v2"/>
|
|
<circle cx="8" cy="12" r="2"/>
|
|
<circle cx="16" cy="12" r="2"/>
|
|
</svg>
|
|
</button>
|
|
<button class="weather-btn" data-weather="snowy" title="下雪">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<line x1="12" y1="2" x2="12" y2="22"/>
|
|
<line x1="2" y1="12" x2="22" y2="12"/>
|
|
<circle cx="6" cy="6" r="1.5" fill="currentColor"/>
|
|
<circle cx="12" cy="18" r="1.5" fill="currentColor"/>
|
|
<circle cx="18" cy="6" r="1.5" fill="currentColor"/>
|
|
</svg>
|
|
</button>
|
|
<button class="weather-btn" data-weather="windy" title="大风">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M9.59 4.59A2 2 0 1 1 11 8H2m10.59 11.41A2 2 0 1 0 14 16H2m15.73-8.27A2.5 2.5 0 1 1 19.5 12H2"/>
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- 详情 -->
|
|
<div class="details fade-transition" id="details">
|
|
<div class="detail-item">
|
|
<svg class="detail-icon" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M12 2.69l5.66 5.66a8 8 0 1 1-11.31 0z"/>
|
|
</svg>
|
|
<div class="detail-value" id="humidity">65%</div>
|
|
<div class="detail-label">湿度</div>
|
|
</div>
|
|
<div class="detail-item">
|
|
<svg class="detail-icon" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M9.59 4.59A2 2 0 1 1 11 8H2m10.59 11.41A2 2 0 1 0 14 16H2"/>
|
|
</svg>
|
|
<div class="detail-value" id="windSpeed">12 km/h</div>
|
|
<div class="detail-label">风速</div>
|
|
</div>
|
|
<div class="detail-item">
|
|
<svg class="detail-icon" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<circle cx="12" cy="12" r="5"/>
|
|
<path d="M12 1v2m0 18v2M4.22 4.22l1.42 1.42m12.72 12.72 1.42 1.42"/>
|
|
</svg>
|
|
<div class="detail-value" id="uvIndex">6</div>
|
|
<div class="detail-label">紫外线</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 闪电层 -->
|
|
<div class="lightning" id="lightning"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// 天气数据配置
|
|
const weatherConfig = {
|
|
sunny: {
|
|
desc: '晴朗',
|
|
temp: 25,
|
|
humidity: '45%',
|
|
windSpeed: '8 km/h',
|
|
uvIndex: '8',
|
|
color: '#ffd93d'
|
|
},
|
|
rainy: {
|
|
desc: '中雨',
|
|
temp: 18,
|
|
humidity: '85%',
|
|
windSpeed: '18 km/h',
|
|
uvIndex: '2',
|
|
color: '#74b9ff'
|
|
},
|
|
snowy: {
|
|
desc: '小雪',
|
|
temp: -2,
|
|
humidity: '70%',
|
|
windSpeed: '10 km/h',
|
|
uvIndex: '3',
|
|
color: '#dfe6e9'
|
|
},
|
|
windy: {
|
|
desc: '大风',
|
|
temp: 14,
|
|
humidity: '55%',
|
|
windSpeed: '32 km/h',
|
|
uvIndex: '4',
|
|
color: '#81ecec'
|
|
}
|
|
};
|
|
|
|
// 动画元素容器
|
|
const canvas = document.getElementById('weatherCanvas');
|
|
const ctx = canvas.getContext('2d');
|
|
let animationParticles = [];
|
|
|
|
// 初始化画布
|
|
function initCanvas() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
|
|
// 创建粒子
|
|
function createParticle(type) {
|
|
const particle = document.createElement('div');
|
|
particle.className = `${type}-particle`;
|
|
particle.style.left = Math.random() * 100 + '%';
|
|
particle.style.animationDuration = (Math.random() * 2 + 2) + 's';
|
|
particle.style.animationDelay = Math.random() * 2 + 's';
|
|
|
|
if (type === 'rain') {
|
|
particle.className = 'rain-drop';
|
|
particle.style.height = (Math.random() * 20 + 10) + 'px';
|
|
particle.style.animationDuration = (Math.random() * 0.5 + 0.5) + 's';
|
|
} else if (type === 'snow') {
|
|
particle.style.width = particle.style.height = (Math.random() * 6 + 4) + 'px';
|
|
particle.style.animationDuration = (Math.random() * 3 + 3) + 's';
|
|
} else if (type === 'leaf') {
|
|
particle.className = 'leaf';
|
|
particle.style.animationDuration = (Math.random() * 3 + 2) + 's';
|
|
particle.style.animationDelay = Math.random() * 2 + 's';
|
|
}
|
|
|
|
canvas.appendChild(particle);
|
|
}
|
|
|
|
// 清除粒子
|
|
function clearParticles() {
|
|
const particles = canvas.querySelectorAll('.rain-drop, .snowflake, .leaf');
|
|
particles.forEach(p => p.remove());
|
|
}
|
|
|
|
// 创建云朵
|
|
function createCloud() {
|
|
const cloud = document.createElement('div');
|
|
cloud.className = 'cloud';
|
|
cloud.style.width = (Math.random() * 100 + 60) + 'px';
|
|
cloud.style.height = (Math.random() * 30 + 20) + 'px';
|
|
cloud.style.top = (Math.random() * 30 - 10) + '%';
|
|
cloud.style.left = (Math.random() * 100 - 50) + '%';
|
|
canvas.appendChild(cloud);
|
|
|
|
setTimeout(() => cloud.remove(), 10000);
|
|
}
|
|
|
|
// 更新天气显示
|
|
function updateWeather(weatherType) {
|
|
const data = weatherConfig[weatherType];
|
|
|
|
// 更新按钮状态
|
|
document.querySelectorAll('.weather-btn').forEach(btn => {
|
|
btn.classList.remove('active');
|
|
if (btn.dataset.weather === weatherType) {
|
|
btn.classList.add('active');
|
|
}
|
|
});
|
|
|
|
// 更新背景
|
|
document.body.setAttribute('data-weather', weatherType);
|
|
|
|
// 更新文字
|
|
document.getElementById('weatherDesc').textContent = data.desc;
|
|
document.getElementById('temperature').innerHTML =
|
|
`${data.temp}<span class="temp-unit">°</span>`;
|
|
document.getElementById('humidity').textContent = data.humidity;
|
|
document.getElementById('windSpeed').textContent = data.windSpeed;
|
|
document.getElementById('uvIndex').textContent = data.uvIndex;
|
|
|
|
// 清除并重建粒子
|
|
clearParticles();
|
|
document.querySelectorAll('.cloud').forEach(c => c.remove());
|
|
|
|
// 根据天气类型创建动画
|
|
switch(weatherType) {
|
|
case 'sunny':
|
|
setInterval(createCloud, 3000);
|
|
document.getElementById('sunElement').style.display = 'block';
|
|
document.getElementById('lightning').style.display = 'none';
|
|
break;
|
|
case 'rainy':
|
|
for (let i = 0; i < 100; i++) {
|
|
setTimeout(() => createParticle('rain'), i * 50);
|
|
}
|
|
document.getElementById('sunElement').style.display = 'none';
|
|
document.getElementById('lightning').style.display = 'block';
|
|
break;
|
|
case 'snowy':
|
|
for (let i = 0; i < 80; i++) {
|
|
setTimeout(() => createParticle('snow'), i * 80);
|
|
}
|
|
document.getElementById('sunElement').style.display = 'none';
|
|
document.getElementById('lightning').style.display = 'none';
|
|
break;
|
|
case 'windy':
|
|
for (let i = 0; i < 30; i++) {
|
|
setTimeout(() => createParticle('leaf'), i * 200);
|
|
}
|
|
document.getElementById('sunElement').style.display = 'none';
|
|
document.getElementById('lightning').style.display = 'none';
|
|
break;
|
|
}
|
|
|
|
// 添加入场动画
|
|
const details = document.getElementById('details');
|
|
details.classList.remove('fade-transition');
|
|
void details.offsetWidth;
|
|
details.classList.add('fade-transition');
|
|
}
|
|
|
|
// 事件监听
|
|
document.querySelectorAll('.weather-btn').forEach(btn => {
|
|
btn.addEventListener('click', () => {
|
|
updateWeather(btn.dataset.weather);
|
|
});
|
|
});
|
|
|
|
// 窗口大小变化
|
|
window.addEventListener('resize', initCanvas);
|
|
|
|
// 初始化
|
|
initCanvas();
|
|
|
|
// 初始动画
|
|
setTimeout(() => createCloud(), 1000);
|
|
</script>
|
|
</body>
|
|
</html>
|