-
Notifications
You must be signed in to change notification settings - Fork 1
/
jq_0707_digital01.html
93 lines (71 loc) · 2.87 KB
/
jq_0707_digital01.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./digital.css">
</head>
<body>
<!-- jQuery Traversing -->
<div class="digiImg">
<!-- 時 -->
<div id="ck1" class="mg1"></div>
<div id="ck2" class="mg2"></div>
<!-- 冒號 mgd-->
<div class="mgd"></div>
<!-- 分 -->
<div id="ck3" class="mg3"></div>
<div id="ck4" class="mg4"></div>
<!-- 冒號 mgd -->
<div class="mgd"></div>
<!-- 秒 -->
<div id="ck5" class="mg5"></div>
<div id="ck6" class="mg6"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
$(document).ready(function () {
function update() {
// 1.抓時間
const nt = new Date();
const nh = nt.getHours();
const nm = nt.getMinutes();
const ns = nt.getSeconds();
console.log('nt', nt);
console.log('nh', nh);
console.log('nm', nm);
console.log('ns', ns);
// 2.時間轉換
// ex. 15:50:30 => 1 5 5 0 3 0
// 抓這幾個數字對應圖片
const nk1 = Math.floor(nh / 10); // 1
const nk2 = nh % 10; // 5
const nk3 = Math.floor(nm / 10); // 5
const nk4 = nm % 10; // 0
const nk5 = Math.floor(ns / 10); // 3
const nk6 = ns % 10; // 0
// 原生JS 時間class放div
document.getElementById('ck1').className = `mg${nk1}`;
document.getElementById('ck2').className = `mg${nk2}`;
document.getElementById('ck3').className = `mg${nk3}`;
document.getElementById('ck4').className = `mg${nk4}`;
document.getElementById('ck5').className = `mg${nk5}`;
document.getElementById('ck6').className = `mg${nk6}`;
document.getElementsByClassName('mgd')[0].style.opacity = 1;
document.getElementsByClassName('mgd')[1].style.opacity = 1;
// 閃爍效果
setTimeout(() => {
document.getElementsByClassName('mgd')[0].style.opacity = 0;
document.getElementsByClassName('mgd')[1].style.opacity = 0;
}, 500);
}
update();
setInterval(update, 1000);
});
</script>
</body>
</html>