-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
51 lines (43 loc) · 1.79 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<main>
<section>
<h1>夏休みまで</h1><br>
<p class="timer">あと<span id="day"></span>日<span id="hour"></span>時間<span id="min"></span>分<span id="sec"></span>秒です!</p>
</section>
</main>
<footer>
<script>
"use strict";
function countdown(due) {
const now = new Date();
const rest = due.getTime() - now.getTime();
const sec = Math.floor(rest / 1000) % 60;
const min = Math.floor(rest / 1000 / 60) % 60;
const hours = Math.floor(rest / 1000 / 60 / 60) % 24;
const day = Math.floor(rest / 1000 / 60 / 60 / 24);
const count = [day, hours, min, sec];
return count;
}
let goal = new Date(2022, 8, 3);
function recalc() {
const counter = countdown(goal);
document.getElementById('day').textContent = counter[0];
document.getElementById('hour').textContent = counter[1];
document.getElementById('min').textContent = String(counter[2]).padStart(2, '0');
document.getElementById('sec').textContent = String(counter[3]).padStart(2, '0');
refresh();
}
function refresh() {
setTimeout(recalc, 1000);
}
recalc();
</script>
</footer>
</body>
</html>