回答編集履歴
1
コード修正および追記
test
CHANGED
@@ -1,3 +1,117 @@
|
|
1
1
|
普通に拝借すればいいのではないでしょうか?
|
2
2
|
|
3
|
-
|
3
|
+
|
4
|
+
|
5
|
+
[https://jsfiddle.net/0kupdr6j/](https://jsfiddle.net/0kupdr6j/)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```HTML
|
10
|
+
|
11
|
+
<div class="target"></div>
|
12
|
+
|
13
|
+
```
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```jQuery
|
18
|
+
|
19
|
+
const countdown_timer = function(){
|
20
|
+
|
21
|
+
let mins = 30; // ここを変えれば指定の minutes にできます
|
22
|
+
|
23
|
+
let secs = mins * 60;
|
24
|
+
|
25
|
+
let msecs = secs * 1000;
|
26
|
+
|
27
|
+
let start_date = new Date();
|
28
|
+
|
29
|
+
let end_date = new Date(start_date.getTime() + msecs);
|
30
|
+
|
31
|
+
let current_mins = 0;
|
32
|
+
|
33
|
+
let current_secs = 0;
|
34
|
+
|
35
|
+
let current_msecs = 0;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
$('.target').append(
|
40
|
+
|
41
|
+
'<div class="countdown_timer">'
|
42
|
+
|
43
|
+
+ '<p class="time">あと<span class="mins">'+mins+'</span>分<span class="secs">00</span>秒<span class="msecs">00</span></p>'
|
44
|
+
|
45
|
+
+ '</div>'
|
46
|
+
|
47
|
+
);
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
if ((navigator.userAgent.indexOf('iPhone') > 0 || navigator.userAgent.indexOf('Android') > 0 && navigator.userAgent.indexOf('Mobile') > 0 || navigator.userAgent.indexOf('iPad') > 0 || navigator.userAgent.indexOf('Android') > 0)) {
|
52
|
+
|
53
|
+
$('.text_attention').html('※このページが表示されてから、<br>60分間の限定割引になります。');
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
let timer = setInterval(function(){
|
60
|
+
|
61
|
+
let now_date = new Date();
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
current_mins = Math.floor(((end_date - now_date) % (24 * 60 * 60 * 1000)) / (60 * 1000)) % 60;
|
66
|
+
|
67
|
+
current_secs = Math.floor(((end_date - now_date) % (24 * 60 * 60 * 1000)) / 1000) % 60 % 60;
|
68
|
+
|
69
|
+
current_msecs = Math.floor(((end_date - now_date) % (24 * 60 * 60 * 1000)) / 10) % 100;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
if(current_mins <= 9) {
|
74
|
+
|
75
|
+
current_mins = "0" + current_mins;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
if(current_secs <= 9) {
|
80
|
+
|
81
|
+
current_secs = "0" + current_secs;
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
if(current_msecs <= 9){
|
86
|
+
|
87
|
+
current_msecs = "0" + current_msecs;
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
$(".time").html(
|
94
|
+
|
95
|
+
'あと'
|
96
|
+
|
97
|
+
+ '<span class="font_size_xl">' + current_mins + '</span>'
|
98
|
+
|
99
|
+
+ '分'
|
100
|
+
|
101
|
+
+ '<span class="font_size_xl">' + current_secs + '</span>'
|
102
|
+
|
103
|
+
+ '秒'
|
104
|
+
|
105
|
+
+ '<span class="font_size_xl">' + current_msecs + '</span>'
|
106
|
+
|
107
|
+
);
|
108
|
+
|
109
|
+
},10);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
countdown_timer();
|
116
|
+
|
117
|
+
```
|