设为首页
收藏本站
隐藏访客:
切换到窄版
账号
自动登录
找回密码
密码
登录
立即注册
快捷导航
论坛
BBS
友情链接
搜索
搜索
本版
帖子
蔡州手游
»
论坛
›
网络资源
›
网络源码
›
一款好看的实时天气html源码
返回列表
发新帖
查看:
32431
|
回复:
0
一款好看的实时天气html源码
[复制链接]
china0396
china0396
当前离线
积分
2037015
打卡等级:暂无等级
打卡总天数:247
打卡月天数:12
打卡总奖励:203
最近打卡:2026-01-21 01:16:29
灌水成绩
15705
58
2037015
主题
帖子
积分
等级头衔
ID :
1
管理员
积分成就
威望 :
999899
点
贡献 :
9999
次
下载币 :
11455
枚
在线时间 : 1257 小时
注册时间 : 2013-9-5
最后登录 : 2026-1-22
发消息
发表于 2025-11-12 18:32:49
|
显示全部楼层
|
阅读模式
免责
长期招聘游戏测试员(无偿),有兴趣联系站长QQ58493525微信A0396C
免费领取大流量卡,每日更新
蔡州手游APP
源码密码
加入群聊
接手游搭建
下载币
购买服务器
[编号:14751]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>实时天气卡片</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f8ff;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.weather-card {
background: white;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
width: 350px;
padding: 20px;
text-align: center;
transition: all 0.3s ease;
}
.weather-card h1 {
font-size: 1.5em;
color: #333;
margin: 0 0 10px;
}
.weather-card p {
font-size: 1em;
color: #555;
margin: 5px 0;
}
.weather-card .weather-info {
font-size: 1.2em;
color: #222;
margin: 15px 0;
}
.weather-card .tip {
font-size: 0.9em;
color: #666;
margin: 10px 0;
}
.weather-card .footer {
font-size: 0.8em;
color: #888;
margin-top: 20px;
}
.weather-card .loading {
font-size: 0.9em;
color: #999;
}
</style>
</head>
<body>
<div class="weather-card">
<h1>实时天气卡片</h1>
<p id="location">📍 <strong>加载中...</strong></p>
<p id="date">📅 <strong>加载中...</strong></p>
<p id="time">⏰ <strong>加载中...</strong></p>
<div class="weather-info">
<p>🌡️ 天气状况:<strong id="weather-status">加载中...</strong></p>
<p>🌡️ 温度:<strong id="temperature">加载中...</strong>℃</p>
<p>💧 湿度:<strong id="humidity">加载中...</strong>%</p>
<p>💨 风向:<strong id="wind-direction">加载中...</strong></p>
<p>💨 风力:<strong id="wind-power">加载中...</strong></p>
</div>
<p class="tip">加载中...</p>
<div class="footer">
<p id="data-source">数据来源:<strong>加载中...</strong></p>
<p id="report-time">报告时间:<strong>加载中...</strong></p>
</div>
<div class="loading">正在加载实时天气数据...</div>
</div>
<script>
// 获取天气数据的API
const API_URL = "https://api.fenx.top/api/getWeather";
// 获取当前时间
function getCurrentTime() {
const now = new Date();
const time = now.toLocaleTimeString();
const date = now.toLocaleDateString();
document.getElementById("time").querySelector("strong").textContent = time;
document.getElementById("date").querySelector("strong").textContent = date;
}
// 更新天气数据
async function fetchWeatherData() {
try {
const response = await fetch(API_URL);
const data = await response.json();
if (data.code === 200) {
const weather = data.data.weather;
const location = `${data.data.province} ${data.data.city}`;
const reportTime = new Date(data.data.weather.reporttime).toLocaleString();
// 更新卡片内容
document.getElementById("location").querySelector("strong").textContent = location;
document.getElementById("weather-status").textContent = weather.weather;
document.getElementById("temperature").textContent = weather.temp;
document.getElementById("humidity").textContent = weather.humidity;
document.getElementById("wind-direction").textContent = weather.winddirection;
document.getElementById("wind-power").textContent = weather.windpower;
document.getElementById("data-source").querySelector("strong").textContent = data.data.ip;
document.getElementById("report-time").querySelector("strong").textContent = reportTime;
document.querySelector(".tip").textContent = "阴天也有它的独特魅力,适合静下心来,享受一段宁静的时光。";
document.querySelector(".loading").style.display = "none";
} else {
throw new Error("Failed to fetch weather data");
}
} catch (error) {
console.error("Error fetching weather data:", error);
document.querySelector(".loading").textContent = "加载失败,请稍后重试。";
}
}
// 初始化
fetchWeatherData();
setInterval(fetchWeatherData, 600000); // 每10分钟更新一次天气数据
setInterval(getCurrentTime, 1000); // 每秒更新时间
</script>
</body>
</html>
复制代码
免责
帖子地址打造全网最多免费游戏网站,部分资源失效,私聊站长补
今日来客
列表模式
回复
使用道具
举报
返回列表
发新帖
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
立即注册
本版积分规则
发表回复
回帖后跳转到最后一页
浏览过的版块
游戏源码
教程
图片视频
单机游戏
|
Archiver
|
手机版
|
小黑屋
|
蔡州手游
|
网站地图
GMT+8, 2026-1-22 01:48