挂件头衔✨️靓标库🧚‍♂️名人堂🦄宝可梦🍎水果机🥊猜拳🏧黑市🏧银行💹抽奖
   🎁
返回列表 发布新帖
查看: 159|回复: 0

[代码技巧] 子比主题 – 侧栏动态时钟与问候语小工具

[复制链接]
社区贡献

331

主题

204

回帖

2万

积分

等级头衔
Icon组别 : 管理员
Icon等级 :

积分成就
   钻石 : 293 颗
   贡献 : 40842 点
   金币 : 24 枚
Icon在线时间 : 1696 小时
Icon注册时间 : 2024-11-22
Icon最后登录 : 2026-6-11

荣誉勋章

连续签到LV.1累计签到LV.3任务·年会员幸运抽奖·皇幸运抽奖·尊幸运抽奖·豪起源之星摩羯座推广LV.2钻石LV.1注册一周年

总共送礼:1 个    总共收礼:0 个

实力·绝代收藏家

飞流名人堂成员 1 FLLTCN 实名认证 特邀大神 诚信商家 信誉担保 精华作者+ 官方团队 vip vip-year 发表于 2025-10-8 21:02:27 | 查看全部 |阅读模式 浙江金华

交易无需等待,成交就是现在,全面资源整合网络大咖云集,让你轻松玩转互联网!

您需要 登录 才可以下载或查看,没有账号?立即注册

×
一个实用又美观的动态时钟和问候语提醒功能,不仅为博客增添人情味,还能与子比主题的深色模式完美兼容! image.webp
[h1]代码部署[/h1]
直接将下面的代码放到:WP后台–>>外观–>>小工具–>>自定义HTML代码即可!
  1. <div class="dynamic-greeting">
  2.         <div class="time-section">
  3.             <div class="time-display">
  4.                 <span id="hours">00</span>
  5.                 <span class="colon">:</span>
  6.                 <span id="minutes">00</span>
  7.                 <span class="colon">:</span>
  8.                 <span id="seconds">00</span>
  9.             </div>
  10.             <div class="date-display" id="date"></div>
  11.         </div>
  12.         <div class="greeting-section">
  13.             <div class="greeting-text" id="greeting"></div>
  14.             <div class="greeting-tip" id="tip"></div>
  15.         </div>
  16.     </div>

  17.     <style>
  18. .dynamic-greeting {background: linear-gradient(145deg, #ffffff, #f0f0f0);border-radius: 15px;padding: 20px;box-shadow: 5px 5px 15px rgba(0,0,0,0.1), -5px -5px 15px rgba(255,255,255,0.8);margin: 20px 0;transition: all 0.3s ease;}.dynamic-greeting:hover {transform: translateY(-2px);box-shadow: 7px 7px 20px rgba(0,0,0,0.12), -7px -7px 20px rgba(255,255,255,0.9);}.time-section {text-align: center;margin-bottom: 15px;padding-bottom: 15px;border-bottom: 1px solid rgba(0,0,0,0.05);}.time-display {font-size: 2.5em;font-weight: 700;color: #007AFF;font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;text-shadow: 2px 2px 4px rgba(0,0,0,0.1);}.time-display .colon {animation: blink 1s infinite;opacity: 1;}@keyframes blink {50% {opacity: 0;}}.date-display {font-size: 1em;color: #666;margin-top: 5px;}.greeting-section {padding: 10px;background: rgba(255,255,255,0.7);border-radius: 10px;}.greeting-text {font-size: 1.2em;color: #333;font-weight: 600;margin-bottom: 8px;}.greeting-tip {font-size: 0.9em;color: #666;line-height: 1.5;}body.dark-theme .dynamic-greeting {background: linear-gradient(145deg, #2d2d2d, #1a1a1a);box-shadow: 5px 5px 15px rgba(0,0,0,0.3), -5px -5px 15px rgba(255,255,255,0.05);}body.dark-theme .time-display {color: #0A84FF;}body.dark-theme .greeting-section {background: rgba(0,0,0,0.2);}body.dark-theme .greeting-text {color: #fff;}body.dark-theme .greeting-tip, body.dark-theme .date-display {color: #999;}
  19.     </style>

  20.     <script>
  21. function updateTime(){const now=new Date();const hours=now.getHours().toString().padStart(2,'0');const minutes=now.getMinutes().toString().padStart(2,'0');const seconds=now.getSeconds().toString().padStart(2,'0');document.getElementById('hours').textContent=hours;document.getElementById('minutes').textContent=minutes;document.getElementById('seconds').textContent=seconds;const options={weekday:'long',year:'numeric',month:'long',day:'numeric'};document.getElementById('date').textContent=now.toLocaleDateString('zh-CN',options)}function updateGreeting(){fetch('https://api.ahfi.cn/api/getGreetingMessage?type=json').then(response=>response.json()).then(data=>{if(data.code===200){document.getElementById('greeting').textContent=data.data.greeting;document.getElementById('tip').textContent=data.data.tip}}).catch(error=>{console.error('获取问候语失败:',error);const hour=new Date().getHours();let defaultGreeting='';if(hour<6)defaultGreeting='凌晨好';else if(hour<11)defaultGreeting='早上好';else if(hour<14)defaultGreeting='中午好';else if(hour<18)defaultGreeting='下午好';else defaultGreeting='晚上好';document.getElementById('greeting').textContent=defaultGreeting;document.getElementById('tip').textContent='愿你今天心情愉快!'})}document.addEventListener('DOMContentLoaded',function(){updateTime();updateGreeting();setInterval(updateTime,1000);setInterval(updateGreeting,60000);if(document.documentElement.getAttribute('data-theme')==='dark'){document.body.classList.add('dark-theme')}});
  22.     </script>
复制代码

本帖被以下淘专辑推荐:

路虽远,行则将至;事虽难,做则必成。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

飞流广播+ 发布

系统消息:飞流安卓客户端APP已上线,请在QQ群(123129)群文件内获取下载。
02-21 02:22
01-24 12:40
站内通告

📢 六月份后均不在线,请悉知

提供资源交易、信息共享、靓号交流、技术变现、学习问答、兴趣娱乐等全面服务。

1.丰富功能系统,扩展社区特色玩法,打造最好的互联网聚集圈子。

2.准确信息真实交易,安全快捷又方便,让虚拟交易面对面。

3. 天上不会掉馅饼,话术骗术迷人心,切勿脱离平台线下交易,被骗与平台无关!

4. 欺诈骗钱,违规违法将视情受到警告&禁言&封号甚至检举至👮🏻‍♀️处理!

官方Q群:1003810038钉推群:BAYR2383 站长QQ:3388700000

飞流论坛(FLLT.CN),一个专注于资源信息发布、虚拟网络交易、技术学习与娱乐社交的交流平台。
  • 钉钉新帖推送群
  • 官方交流QQ群
  • 站长唯一微信号

💥客户端|🧿小黑屋|📴手机页|飞流网 |网站地图

GMT+8, 2026-6-12 07:32 , Processed in 0.079563 second(s), 84 queries, MemCached On , Gzip On.

飞流论坛 HanAnalytics icp

Copyright © 2024-2026 飞流网 版权所有 All Rights Reserved. X3.5

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