質問編集履歴
2
再修正した
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,7 +50,7 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
##
|
53
|
+
## 再修正
|
54
54
|
|
55
55
|
|
56
56
|
|
@@ -60,11 +60,11 @@
|
|
60
60
|
|
61
61
|
const start_time = new Date(document.getElementById('start_time').dataset.time);
|
62
62
|
|
63
|
+
const countdown = () => {
|
64
|
+
|
63
65
|
const current_time = new Date(document.getElementById('current_time').dataset.time);
|
64
66
|
|
65
67
|
var diff = start_time - current_time;
|
66
|
-
|
67
|
-
const countdown = () => {
|
68
68
|
|
69
69
|
if (diff <= 0) {
|
70
70
|
|
1
変更点の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -47,3 +47,53 @@
|
|
47
47
|
カウントダウンを出しているviewにTime.currentを置いたのですが、毎秒とることができないので詰まっています。
|
48
48
|
|
49
49
|
どなたかご教授お願いします。
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
##変更点
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
// start_timeとcurrent_timeはviewから取っています。
|
60
|
+
|
61
|
+
const start_time = new Date(document.getElementById('start_time').dataset.time);
|
62
|
+
|
63
|
+
const current_time = new Date(document.getElementById('current_time').dataset.time);
|
64
|
+
|
65
|
+
var diff = start_time - current_time;
|
66
|
+
|
67
|
+
const countdown = () => {
|
68
|
+
|
69
|
+
if (diff <= 0) {
|
70
|
+
|
71
|
+
alert('セール開始です!');
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
const diff_sec = Math.floor(diff / 1000) % 60;
|
76
|
+
|
77
|
+
const diff_min = Math.floor(diff / 1000 / 60) % 60;
|
78
|
+
|
79
|
+
const diff_hour = Math.floor(diff / 1000 / 60 / 60) % 24;
|
80
|
+
|
81
|
+
const diff_day = Math.floor(diff / 1000 / 60 / 60 / 24);
|
82
|
+
|
83
|
+
document.getElementById('min').textContent = String(diff_min).padStart(2, '0');
|
84
|
+
|
85
|
+
document.getElementById('sec').textContent = String(diff_sec).padStart(2, '0');
|
86
|
+
|
87
|
+
document.getElementById('hour').textContent = String(diff_hour).padStart(2, '0');
|
88
|
+
|
89
|
+
document.getElementById('day').textContent = String(diff_day).padStart(2, '0');
|
90
|
+
|
91
|
+
diff --;
|
92
|
+
|
93
|
+
setTimeout(countdown, 1000);
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
countdown();
|
98
|
+
|
99
|
+
```
|