找回密码
 立即注册
搜索
查看: 1089|回复: 0

一款好看的实时天气html源码

[复制链接]
  • 打卡等级:暂无等级
  • 打卡总天数:189
  • 打卡月天数:13
  • 打卡总奖励:145
  • 最近打卡:2025-11-13 10:56:25
灌水成绩
13861
48
2034798
主题
帖子
积分

等级头衔

ID : 1

管理员

积分成就 威望 : 999999
贡献 : 9999
下载币 : 10892
在线时间 : 1011 小时
注册时间 : 2013-9-5
最后登录 : 2025-11-13

发表于 昨天 18:32 | 显示全部楼层 |阅读模式 IP:广东东莞
免责
免费领取大流量卡,每日更新蔡州手游APP源码密码加入群聊接手游搭建—``下载币--购买服务器☆长期招聘游戏测试员(无偿),有兴趣联系站长QQ58493525微信A0396C
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>实时天气卡片</title>
  7.     <style>
  8.         body {
  9.             font-family: Arial, sans-serif;
  10.             background-color: #f0f8ff;
  11.             margin: 0;
  12.             padding: 0;
  13.             display: flex;
  14.             justify-content: center;
  15.             align-items: center;
  16.             height: 100vh;
  17.         }
  18.         .weather-card {
  19.             background: white;
  20.             border-radius: 10px;
  21.             box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  22.             width: 350px;
  23.             padding: 20px;
  24.             text-align: center;
  25.             transition: all 0.3s ease;
  26.         }
  27.         .weather-card h1 {
  28.             font-size: 1.5em;
  29.             color: #333;
  30.             margin: 0 0 10px;
  31.         }
  32.         .weather-card p {
  33.             font-size: 1em;
  34.             color: #555;
  35.             margin: 5px 0;
  36.         }
  37.         .weather-card .weather-info {
  38.             font-size: 1.2em;
  39.             color: #222;
  40.             margin: 15px 0;
  41.         }
  42.         .weather-card .tip {
  43.             font-size: 0.9em;
  44.             color: #666;
  45.             margin: 10px 0;
  46.         }
  47.         .weather-card .footer {
  48.             font-size: 0.8em;
  49.             color: #888;
  50.             margin-top: 20px;
  51.         }
  52.         .weather-card .loading {
  53.             font-size: 0.9em;
  54.             color: #999;
  55.         }
  56.     </style>
  57. </head>
  58. <body>
  59.     <div class="weather-card">
  60.         <h1>实时天气卡片</h1>
  61.         <p id="location">📍 <strong>加载中...</strong></p>
  62.         <p id="date">📅 <strong>加载中...</strong></p>
  63.         <p id="time">⏰ <strong>加载中...</strong></p>
  64.         <div class="weather-info">
  65.             <p>🌡️ 天气状况:<strong id="weather-status">加载中...</strong></p>
  66.             <p>🌡️ 温度:<strong id="temperature">加载中...</strong>℃</p>
  67.             <p>💧 湿度:<strong id="humidity">加载中...</strong>%</p>
  68.             <p>💨 风向:<strong id="wind-direction">加载中...</strong></p>
  69.             <p>💨 风力:<strong id="wind-power">加载中...</strong></p>
  70.         </div>
  71.         <p class="tip">加载中...</p>
  72.         <div class="footer">
  73.             <p id="data-source">数据来源:<strong>加载中...</strong></p>
  74.             <p id="report-time">报告时间:<strong>加载中...</strong></p>
  75.         </div>
  76.         <div class="loading">正在加载实时天气数据...</div>
  77.     </div>

  78.     <script>
  79.         // 获取天气数据的API
  80.         const API_URL = "https://api.fenx.top/api/getWeather";

  81.         // 获取当前时间
  82.         function getCurrentTime() {
  83.             const now = new Date();
  84.             const time = now.toLocaleTimeString();
  85.             const date = now.toLocaleDateString();
  86.             document.getElementById("time").querySelector("strong").textContent = time;
  87.             document.getElementById("date").querySelector("strong").textContent = date;
  88.         }

  89.         // 更新天气数据
  90.         async function fetchWeatherData() {
  91.             try {
  92.                 const response = await fetch(API_URL);
  93.                 const data = await response.json();
  94.                 if (data.code === 200) {
  95.                     const weather = data.data.weather;
  96.                     const location = `${data.data.province} ${data.data.city}`;
  97.                     const reportTime = new Date(data.data.weather.reporttime).toLocaleString();

  98.                     // 更新卡片内容
  99.                     document.getElementById("location").querySelector("strong").textContent = location;
  100.                     document.getElementById("weather-status").textContent = weather.weather;
  101.                     document.getElementById("temperature").textContent = weather.temp;
  102.                     document.getElementById("humidity").textContent = weather.humidity;
  103.                     document.getElementById("wind-direction").textContent = weather.winddirection;
  104.                     document.getElementById("wind-power").textContent = weather.windpower;
  105.                     document.getElementById("data-source").querySelector("strong").textContent = data.data.ip;
  106.                     document.getElementById("report-time").querySelector("strong").textContent = reportTime;
  107.                     document.querySelector(".tip").textContent = "阴天也有它的独特魅力,适合静下心来,享受一段宁静的时光。";
  108.                     document.querySelector(".loading").style.display = "none";
  109.                 } else {
  110.                     throw new Error("Failed to fetch weather data");
  111.                 }
  112.             } catch (error) {
  113.                 console.error("Error fetching weather data:", error);
  114.                 document.querySelector(".loading").textContent = "加载失败,请稍后重试。";
  115.             }
  116.         }

  117.         // 初始化
  118.         fetchWeatherData();
  119.         setInterval(fetchWeatherData, 600000); // 每10分钟更新一次天气数据
  120.         setInterval(getCurrentTime, 1000); // 每秒更新时间
  121.     </script>
  122. </body>
  123. </html>
复制代码


免责
帖子地址打造全网最多免费游戏网站
今日来客 列表模式
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

本站已运行 ©2013-2026

QQ|Archiver|手机版|小黑屋|蔡州手游 |网站地图

GMT+8, 2025-11-13 15:49

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表