当前位置:   article > 正文

原神自定义倒计时

原神自定义倒计时

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>原神倒计时</title>
  6. <style>
  7. * {
  8. margin: 0;
  9. padding: 0;
  10. box-sizing: border-box;
  11. user-select: none;
  12. body {
  13. background: #0b1b2c;
  14. }
  15. }
  16. header {
  17. width: 100vw;
  18. height: 40px;
  19. display: flex;
  20. justify-content: space-between;
  21. align-items: center;
  22. background-color: #cbcbcb;
  23. /* logo */
  24. figure.logo {
  25. width: 262px;
  26. height: 50px;
  27. /* 缩小 */
  28. transform: scale(0.8);
  29. margin-top: 2px;
  30. margin-left: -15px;
  31. border-radius: 50%;
  32. background: #f30303;
  33. box-shadow: inset 4px 4px 4px rgba(255, 255, 255, 0.6),
  34. inset -4px -4px 5px rgba(0, 0, 0, 0.6);
  35. z-index: 99;
  36. figcaption {
  37. background: hsl(0, 0%, 0%);
  38. background-clip: text;
  39. -webkit-background-clip: text;
  40. -webkit-text-fill-color: transparent;
  41. font-weight: bold;
  42. box-shadow: inset 4px 4px 4px rgba(255, 255, 255, 0.6), inset -4px -4px 5px rgba(0, 0, 0, 0.6);
  43. letter-spacing: -3px;
  44. line-height: 45px;
  45. border-radius: 50%;
  46. font-size: 40px;
  47. width: 152px;
  48. }
  49. .my_name1 {
  50. text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.726);
  51. clip-path: polygon(0% 0%, 100% 0%, 100% 50%, 0% 50%);
  52. transform: translate(35%, 0%);
  53. }
  54. .my_name2 {
  55. text-shadow: 1px 1px 1px hsla(160, 100%, 37%, 0.555);
  56. clip-path: polygon(0% 50%, 100% 50%, 100% 100%, 0% 100%);
  57. transform: translate(35%, -93%);
  58. }
  59. img {
  60. width: 60px;
  61. height: 35px;
  62. border-radius: 50%;
  63. transition: transform 0.3s ease;
  64. position: absolute;
  65. &:hover {
  66. transform: scale(1.3);
  67. filter: drop-shadow(0 0 0.3em #ff0202);
  68. }
  69. }
  70. .kong {
  71. margin-top: 7px;
  72. margin-left: 200px;
  73. }
  74. .ying {
  75. top: 7px;
  76. margin-left: 2px;
  77. }
  78. }
  79. /* 时间 */
  80. time {
  81. background: -webkit-linear-gradient(315deg, #e1ff00 50%, #ff0000);
  82. background-clip: text;
  83. -webkit-background-clip: text;
  84. -webkit-text-fill-color: transparent;
  85. font-size: 1.5rem;
  86. font-weight: 900;
  87. text-shadow: 2px -1px 8px rgba(250, 80, 193, 0.323);
  88. sub {
  89. -webkit-text-fill-color: #cfd601;
  90. text-shadow: 1px 1px 1px #100000;
  91. font-size: 1rem;
  92. }
  93. }
  94. /* 全屏还原关闭按钮 */
  95. menu {
  96. display: flex;
  97. button {
  98. background: none;
  99. border: none;
  100. }
  101. img {
  102. width: 35px;
  103. margin-top: 5px;
  104. margin-right: 5px;
  105. cursor: pointer;
  106. &:hover {
  107. transform: scale(1.2);
  108. padding: 5px;
  109. background: #ffd000;
  110. }
  111. }
  112. button:nth-child(2) {
  113. display: none;
  114. /* 放大镜效果 */
  115. transform: scale(1.16);
  116. }
  117. }
  118. }
  119. main {
  120. display: flex;
  121. flex-direction: column;
  122. align-items: center;
  123. #countdownContainer {
  124. display: flex;
  125. flex-direction: column;
  126. align-items: center;
  127. button {
  128. font-size: 1.5rem;
  129. color: hsla(160, 100%, 37%, 0.63);
  130. text-shadow: 1px 1px 1px #100000;
  131. cursor: pointer;
  132. border-radius: 3px;
  133. /* background-color: #f30303; */
  134. border: none;
  135. margin: 5px;
  136. padding: 3px;
  137. }
  138. dialog {
  139. transform: translate(180%, 80%);
  140. }
  141. dialog::backdrop {
  142. /* 模糊背景 */
  143. backdrop-filter: blur(2px);
  144. }
  145. }
  146. table {
  147. border-collapse: collapse;
  148. th,
  149. td {
  150. text-align: center;
  151. padding: 8px;
  152. border: 1px solid #ddd;
  153. }
  154. th {
  155. background-color: #9f9e9e;
  156. }
  157. td {
  158. color: hsl(160, 100%, 37%);
  159. text-shadow: 1px 1px 1px #030303;
  160. }
  161. }
  162. }
  163. </style>
  164. </head>
  165. <body>
  166. <header>
  167. <!-- logo -->
  168. <figure class="logo">
  169. <a href="https://blog.csdn.net/lulei5153?spm=1011.2415.3001.5343" title="与妖为邻CSDN博客" target="_blank">
  170. <img class="kong" src="file:///D:/img/icon.ico" alt="与妖为邻">
  171. </a>
  172. <figcaption class="my_name1">与妖为邻</figcaption>
  173. <figcaption class="my_name2">与妖为邻</figcaption>
  174. <a href="file:///D:/web/html%E9%A6%96%E9%A1%B5/%E5%A4%87%E5%BF%98%E5%BD%95.html" class="home_page"
  175. title="首页" target="_blank">
  176. <img class="ying" src="file:///D:/img/ying.png" alt="与妖为邻">
  177. </a>
  178. </figure>
  179. <!-- 时间 -->
  180. <time datetime="2024-07-10" title="2024-07-10" id="dateTime">2024-07-10</time>
  181. <!-- 天气 -->
  182. <iframe class="tianqi" frameborder="0" width="280" height="36" scrolling="no" hspace="0"
  183. src="https://i.tianqi.com/?c=code&id=99">
  184. </iframe>
  185. <!-- 全屏还原关闭按钮 -->
  186. <menu>
  187. <button class="fullScreen" type="button"><img src="file:///D:/img/全屏.svg" alt="全屏"
  188. onclick="fullScreen()"></button>
  189. <button class="exitFullScreen" type="button"><img src="file:///D:/img/还原.svg" alt="还原"
  190. onclick="exitFullScreen()"></button>
  191. <button type="button"><img src="file:///D:/img/关闭.svg" alt="关闭" onclick="closeAll()"> </button>
  192. </menu>
  193. </header>
  194. <main>
  195. <div id="countdownContainer"></div>
  196. <table id="characterTable">
  197. <tr>
  198. <th>序号</th>
  199. <th>元素</th>
  200. <th>角色</th>
  201. <th>等级</th>
  202. <th>命座</th>
  203. <th>天赋</th>
  204. <th>备注</th>
  205. </tr>
  206. </table>
  207. </main>
  208. </body>
  209. <script>
  210. /* 现在时间*/
  211. var current_time = document.getElementById("dateTime");
  212. function showTime() {
  213. var now = new Date();
  214. var year = now.getFullYear();
  215. var month = ("0" + (now.getMonth() + 1)).slice(-2);
  216. var day = ("0" + now.getDate()).slice(-2);
  217. var hour = ("0" + now.getHours()).slice(-2);
  218. var min = ("0" + now.getMinutes()).slice(-2);
  219. var second = ("0" + now.getSeconds()).slice(-2);
  220. var week = [
  221. "星期日",
  222. "星期一",
  223. "星期二",
  224. "星期三",
  225. "星期四",
  226. "星期五",
  227. "星期六",
  228. ][now.getDay()];
  229. var time = `${year}-${month}-${day}<sub id='sub'>${week}</sub> ${hour}:${min}:${second}`;
  230. current_time.innerHTML = time;
  231. }
  232. showTime();
  233. setInterval(showTime, 1000);
  234. /* 现在时间 结束*/
  235. /* 全屏功能与关闭*/
  236. function fullScreen() {
  237. var elem = document.documentElement;
  238. if (elem.requestFullscreen) {
  239. elem.requestFullscreen();
  240. } else if (elem.mozRequestFullScreen) { // Firefox
  241. elem.mozRequestFullScreen();
  242. } else if (elem.webkitRequestFullscreen) { // Chrome, Safari and Opera
  243. elem.webkitRequestFullscreen();
  244. } else if (elem.msRequestFullscreen) { // IE/Edge
  245. elem.msRequestFullscreen();
  246. }
  247. }
  248. function exitFullScreen() {
  249. if (document.exitFullscreen) {
  250. document.exitFullscreen();
  251. } else if (document.mozCancelFullScreen) { // Firefox
  252. document.mozCancelFullScreen();
  253. } else if (document.webkitExitFullscreen) { // Chrome, Safari and Opera
  254. document.webkitExitFullscreen();
  255. } else if (document.msExitFullscreen) { // IE/Edge
  256. document.msExitFullscreen();
  257. }
  258. }
  259. // 获取全屏和还原按钮
  260. var fullScreenBtn = document.querySelector(".fullScreen");
  261. var exitFullScreenBtn = document.querySelector(".exitFullScreen");
  262. // 监听全屏和还原事件
  263. document.addEventListener("fullscreenchange", function () {
  264. if (document.fullscreenElement) {
  265. fullScreenBtn.style.display = "none";
  266. exitFullScreenBtn.style.display = "block";
  267. } else {
  268. fullScreenBtn.style.display = "block";
  269. exitFullScreenBtn.style.display = "none";
  270. }
  271. });
  272. // 关闭当前窗口
  273. function closeAll() {
  274. window.close();
  275. }
  276. /* 全屏功能与关闭 结束*/
  277. /* 倒计时功能渲染*/
  278. const countdownContainer = document.getElementById('countdownContainer');
  279. function createCountdownElement(id) {
  280. const button = document.createElement('button');
  281. button.textContent = `第${id}个倒计时`;
  282. button.id = `countdownElement${id}`;
  283. button.onclick = () => document.getElementById(`dialogCountdownElement${id}`).showModal();
  284. const dialog = document.createElement('dialog');
  285. dialog.id = `dialogCountdownElement${id}`;
  286. const form = document.createElement('form');
  287. form.method = 'dialog';
  288. const messageDiv = document.createElement('div');
  289. const messageLabel = document.createElement('label');
  290. messageLabel.textContent = '更改提示信息:';
  291. messageLabel.htmlFor = `message${id}`;
  292. const messageInput = document.createElement('input');
  293. messageInput.type = 'text';
  294. messageInput.id = `message${id}`;
  295. messageInput.value = '距离2024年国庆节还有:';
  296. messageDiv.appendChild(messageLabel);
  297. messageDiv.appendChild(messageInput);
  298. const targetDateDiv = document.createElement('div');
  299. const targetDateLabel = document.createElement('label');
  300. targetDateLabel.textContent = '更改目标日期:';
  301. targetDateLabel.htmlFor = `targetDate${id}`;
  302. const targetDateInput = document.createElement('input');
  303. targetDateInput.type = 'datetime-local';
  304. targetDateInput.id = `targetDate${id}`;
  305. targetDateDiv.appendChild(targetDateLabel);
  306. targetDateDiv.appendChild(targetDateInput);
  307. const closeButton = document.createElement('button');
  308. closeButton.type = 'submit';
  309. closeButton.textContent = '关闭';
  310. closeButton.style.display = 'block';
  311. closeButton.style.margin = '5px auto';
  312. form.appendChild(messageDiv);
  313. form.appendChild(targetDateDiv);
  314. form.appendChild(closeButton);
  315. dialog.appendChild(form);
  316. countdownContainer.appendChild(button);
  317. countdownContainer.appendChild(dialog);
  318. }
  319. for (let i = 1; i <= 4; i++) {
  320. createCountdownElement(i);
  321. }
  322. /* 倒计时功能渲染 结束*/
  323. /* 倒计时功能实现*/
  324. const countdownData = {
  325. 1: { message: 'message1', targetDate: 'targetDate1' },
  326. 2: { message: 'message2', targetDate: 'targetDate2' },
  327. 3: { message: 'message3', targetDate: 'targetDate3' },
  328. 4: { message: 'message4', targetDate: 'targetDate4' }
  329. };
  330. // 加载时从localStorage读取数据
  331. window.onload = function () {
  332. for (let id in countdownData) {
  333. const message = localStorage.getItem(countdownData[id].message);
  334. const targetDate = localStorage.getItem(countdownData[id].targetDate);
  335. if (message) {
  336. document.getElementById(countdownData[id].message).value = message;
  337. }
  338. if (targetDate) {
  339. document.getElementById(countdownData[id].targetDate).value = targetDate;
  340. }
  341. }
  342. };
  343. // 保存数据到localStorage
  344. function saveData(id) {
  345. const message = document.getElementById(countdownData[id].message).value;
  346. const targetDate = document.getElementById(countdownData[id].targetDate).value;
  347. localStorage.setItem(countdownData[id].message, message);
  348. localStorage.setItem(countdownData[id].targetDate, targetDate);
  349. }
  350. // 监听输入框的变化并保存数据
  351. for (let id in countdownData) {
  352. document.getElementById(countdownData[id].message).addEventListener('input', () => saveData(id));
  353. document.getElementById(countdownData[id].targetDate).addEventListener('input', () => saveData(id));
  354. }
  355. function showCountdown(id) {
  356. const message = document.getElementById(countdownData[id].message).value;
  357. const targetDateInput = document.getElementById(countdownData[id].targetDate);
  358. const targetDateValue = targetDateInput.value;
  359. const now = new Date();
  360. let targetDate;
  361. if (targetDateValue) {
  362. targetDate = new Date(targetDateValue);
  363. } else {
  364. targetDate = new Date(2024, 9, 1); // 默认值:2024年10月1日
  365. }
  366. const diff = targetDate - now;
  367. const days = Math.floor(diff / (1000 * 60 * 60 * 24));
  368. const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  369. const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
  370. const seconds = Math.floor((diff % (1000 * 60)) / 1000);
  371. const countdownElement = document.getElementById(`countdownElement${id}`);
  372. countdownElement.innerHTML = `${message}${days}${hours}小时${minutes}${seconds}秒`;
  373. }
  374. for (let id in countdownData) {
  375. showCountdown(id);
  376. setInterval(() => showCountdown(id), 1000);
  377. }
  378. /* 倒计时功能实现 结束*/
  379. // 原神角色数据
  380. const data = [
  381. {
  382. "element": "火",
  383. characters: [
  384. {
  385. "role": "班尼特",
  386. "level": 90,
  387. "constellation": "5",
  388. "talent": "10-13-13",
  389. "note": "4宗室"
  390. },
  391. {
  392. "role": "霄宫",
  393. "level": 90,
  394. "constellation": "1",
  395. "talent": "10-10-10",
  396. "note": "五追忆"
  397. },
  398. {
  399. "role": "香菱",
  400. "level": 90,
  401. "constellation": "3",
  402. "talent": "1-7-12",
  403. "note": "五绝缘"
  404. },
  405. ]
  406. },
  407. {
  408. "element": "水",
  409. characters: [
  410. {
  411. "role": "夜兰",
  412. "level": 90,
  413. "constellation": "1",
  414. "talent": "10-10-10",
  415. "note": "五绝缘"
  416. },
  417. {
  418. "role": "珊瑚宫心海",
  419. "level": 90,
  420. "constellation": "0",
  421. "talent": "7-10-8",
  422. "note": "4海染"
  423. }
  424. ]
  425. },
  426. {
  427. "element": "风",
  428. characters: [
  429. {
  430. "role": "枫原万叶",
  431. "level": 90,
  432. "constellation": "1",
  433. "talent": "10-10-10",
  434. "note": "4翠绿"
  435. },
  436. {
  437. "role": "流浪者",
  438. "level": 90,
  439. "constellation": "0",
  440. "talent": "10-10-10",
  441. "note": "五沙上"
  442. }
  443. ]
  444. },
  445. {
  446. "element": "雷",
  447. characters: [
  448. {
  449. "role": "雷电将军",
  450. "level": 90,
  451. "constellation": "3",
  452. "talent": "10-10-13",
  453. "note": "五绝缘"
  454. },
  455. {
  456. "role": "刻晴",
  457. "level": 90,
  458. "constellation": "1",
  459. "talent": "1-1-1",
  460. "note": "无"
  461. },
  462. ]
  463. },
  464. {
  465. "element": "草",
  466. characters: [
  467. {
  468. "role": "纳西妲",
  469. "level": 90,
  470. "constellation": "0",
  471. "talent": "9-10-9",
  472. "note": "5深林"
  473. },
  474. {
  475. "role": "提纳里",
  476. "level": 70,
  477. "constellation": "2",
  478. "talent": "1-1-1",
  479. "note": "无"
  480. },
  481. ]
  482. },
  483. {
  484. "element": "冰",
  485. characters: [
  486. {
  487. "role": "七七",
  488. "level": 90,
  489. "constellation": "1",
  490. "talent": "9-10-9",
  491. "note": "五海染"
  492. },
  493. {
  494. "role": "迪奥娜",
  495. "level": 90,
  496. "constellation": "6",
  497. "talent": "1-9-9",
  498. "note": "2千岩2海染"
  499. }
  500. ]
  501. },
  502. {
  503. "element": "岩",
  504. characters: [
  505. {
  506. "role": "钟离",
  507. "level": 90,
  508. "constellation": "0",
  509. "talent": "9-10-10",
  510. "note": "五千岩"
  511. },
  512. {
  513. "role": "凝光",
  514. "level": 70,
  515. "constellation": "6",
  516. "talent": "1-4-4",
  517. "note": "无"
  518. }
  519. ]
  520. },
  521. ];
  522. // 获取页面上的表格元素
  523. const characterTable = document.getElementById("characterTable");
  524. // 初始化行号
  525. let row = 1;
  526. // 记录上一个元素
  527. let lastElement = null;
  528. // 记录元素的行跨度
  529. let elementRowSpan = 1;
  530. // 遍历数据
  531. for (let i = 0; i < data.length; i++) {
  532. const elementData = data[i];
  533. // 遍历每个元素的角色数据
  534. for (let j = 0; j < elementData.characters.length; j++) {
  535. const character = elementData.characters[j];
  536. const newRow = characterTable.insertRow();
  537. newRow.insertCell().textContent = row++;
  538. // 如果元素与上一个元素不同,则插入新的元素单元格,并设置行跨度
  539. if (elementData.element !== lastElement) {
  540. const elementCell = newRow.insertCell();
  541. elementCell.rowSpan = elementData.characters.length;
  542. elementCell.textContent = elementData.element;
  543. lastElement = elementData.element;
  544. }
  545. newRow.insertCell().textContent = character.role;
  546. newRow.insertCell().textContent = character.level;
  547. newRow.insertCell().textContent = character.constellation;
  548. newRow.insertCell().textContent = character.talent;
  549. newRow.insertCell().textContent = character.note;
  550. // 根据元素类型设置背景颜色
  551. // 根据元素类型设置背景颜色
  552. /*
  553. 原神中的七大元素颜色分别为:‌
  554. 火(‌红色)‌、‌水(‌蓝色)‌、‌风(‌青色)‌、‌雷(‌紫色)‌、‌草(‌绿色)‌、‌冰(‌浅蓝色)‌、‌岩(‌黄色)‌。‌
  555. */
  556. switch (elementData.element) {
  557. case "火":
  558. newRow.style.backgroundColor = "#FF0000"; // 红色
  559. break;
  560. case "水":
  561. newRow.style.backgroundColor = "#0000FF"; // 蓝色
  562. break;
  563. case "风":
  564. newRow.style.backgroundColor = "#00FFFF"; // 青色
  565. break;
  566. case "雷":
  567. newRow.style.backgroundColor = "#800080"; // 紫色
  568. break;
  569. case "草":
  570. newRow.style.backgroundColor = "#008000"; // 深绿色
  571. break;
  572. case "冰":
  573. newRow.style.backgroundColor = "#ADD8E6"; // 浅蓝色
  574. break;
  575. case "岩":
  576. newRow.style.backgroundColor = "#FFFF00"; // 黄色
  577. break;
  578. }
  579. }
  580. }
  581. </script>
  582. </html>

 

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号