質問編集履歴
1
追加の情報、具体的にソースを書きました(実戦に近い状態)
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,15 +2,19 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
5
|
+
<div class="lp_timer">
|
6
|
+
|
6
|
-
|
7
|
+
<div class="cdown" data-cdown-min="15"></div>
|
8
|
+
|
9
|
+
</div>
|
10
|
+
|
11
|
+
|
12
|
+
|
7
|
-
<
|
13
|
+
<p class="cp_bnr"><img src="img/timer_15min_bnr.jpg" ></p>
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
14
18
|
|
15
19
|
|
16
20
|
|
@@ -26,35 +30,191 @@
|
|
26
30
|
|
27
31
|
|
28
32
|
|
29
|
-
.
|
33
|
+
.lp_timer {
|
34
|
+
|
35
|
+
background: url("../img/timer_15min_bg.jpg")no-repeat center top;
|
36
|
+
|
37
|
+
background-size: 100%;
|
38
|
+
|
39
|
+
height: 20vw;
|
40
|
+
|
41
|
+
width: 100%;
|
42
|
+
|
43
|
+
overflow: hidden;
|
30
44
|
|
31
45
|
position: fixed;
|
32
46
|
|
33
47
|
z-index: 100;
|
34
48
|
|
35
|
-
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
.cdown,
|
54
|
+
|
55
|
+
.cdown-done,
|
56
|
+
|
57
|
+
.cdown-loop {
|
58
|
+
|
59
|
+
font-size: 7vw;
|
60
|
+
|
61
|
+
color: #FDF051;
|
62
|
+
|
63
|
+
font-weight: bold;
|
64
|
+
|
65
|
+
position: relative;
|
66
|
+
|
67
|
+
top: 12vw;
|
68
|
+
|
69
|
+
left: 34vw;
|
70
|
+
|
71
|
+
width: 100%;
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
.cp_bnr{
|
80
|
+
|
81
|
+
margin-top: 10vw;
|
36
82
|
|
37
83
|
}
|
38
84
|
|
39
85
|
|
40
86
|
|
41
|
-
|
87
|
+
|
42
|
-
|
43
|
-
margin: 100px;
|
44
|
-
|
45
|
-
}
|
46
88
|
|
47
89
|
```
|
48
90
|
|
49
91
|
|
50
92
|
|
93
|
+
|
94
|
+
|
95
|
+
```javascript
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
window.addEventListener(
|
100
|
+
|
101
|
+
"load",
|
102
|
+
|
103
|
+
function() {
|
104
|
+
|
105
|
+
var cdown = new Object();
|
106
|
+
|
107
|
+
cdown.elem = document.querySelectorAll(".cdown");
|
108
|
+
|
109
|
+
cdown.tmr = new Array();
|
110
|
+
|
111
|
+
cdown.getTime = function(I) {
|
112
|
+
|
113
|
+
var attributes = cdown.elem[I].attributes;
|
114
|
+
|
115
|
+
for (var type, value, i = 0; i < attributes.length; i++) {
|
116
|
+
|
117
|
+
type = attributes[i].name.match(/(^data-cdown-)(.+)/);
|
118
|
+
|
119
|
+
if (type) {
|
120
|
+
|
121
|
+
value = parseInt(attributes[i].value, 10) || 0;
|
122
|
+
|
123
|
+
return type[2] == "min" ? value * 60 : value;
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
return null;
|
130
|
+
|
131
|
+
};
|
132
|
+
|
133
|
+
cdown.start = function(I) {
|
134
|
+
|
135
|
+
var sec = cdown.getTime(I);
|
136
|
+
|
137
|
+
if (sec == null) {
|
138
|
+
|
139
|
+
return;
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
var target = new Date().getTime() + sec * 1000;
|
144
|
+
|
145
|
+
cdown.tmr[I] = setInterval(function() {
|
146
|
+
|
147
|
+
var now = new Date().getTime();
|
148
|
+
|
149
|
+
var left = target - now;
|
150
|
+
|
151
|
+
var output = {
|
152
|
+
|
153
|
+
min: Math.floor((left % (1000 * 60 * 60)) / (1000 * 60)),
|
154
|
+
|
155
|
+
sec: Math.floor((left % (1000 * 60)) / 1000),
|
156
|
+
|
157
|
+
ms: left % 1000,
|
158
|
+
|
159
|
+
};
|
160
|
+
|
161
|
+
console.log(left);
|
162
|
+
|
163
|
+
if (left > 0) {
|
164
|
+
|
165
|
+
cdown.elem[I].textContent = "" + ("0" + output.min).slice(-2) + " : " + ("0" + output.sec).slice(-2) + " : " + ("00" + output.ms).slice(-2);
|
166
|
+
|
167
|
+
} else {
|
168
|
+
|
169
|
+
cdown.elem[I].textContent = "0:00"; // 終了後に表示される言葉
|
170
|
+
|
171
|
+
window.clearInterval(cdown.tmr[I]);
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
}, 20);
|
176
|
+
|
177
|
+
};
|
178
|
+
|
179
|
+
for (var i = 0; i < cdown.elem.length; i++) {
|
180
|
+
|
181
|
+
cdown.start(i);
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
},
|
186
|
+
|
187
|
+
false
|
188
|
+
|
189
|
+
);
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
```
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
51
211
|
上記コードのように画像が上下2枚の構成で、上の画像をフローティングした時に
|
52
212
|
|
53
|
-
下の画像が被ってしまうので
|
213
|
+
下の画像 cp_bnr が被ってしまうので
|
54
|
-
|
55
|
-
|
56
|
-
|
214
|
+
|
215
|
+
|
216
|
+
|
57
|
-
|
217
|
+
フローティング要素の下の画像 cp_bnr に
|
58
218
|
|
59
219
|
|
60
220
|
|
@@ -70,11 +230,11 @@
|
|
70
230
|
|
71
231
|
|
72
232
|
|
73
|
-
.
|
233
|
+
.cp_bnr img
|
74
234
|
|
75
235
|
や
|
76
236
|
|
77
|
-
img.
|
237
|
+
img.cp_bnr
|
78
238
|
|
79
239
|
|
80
240
|
|
@@ -92,16 +252,18 @@
|
|
92
252
|
|
93
253
|
|
94
254
|
|
95
|
-
.
|
255
|
+
.cp_bnr
|
96
256
|
|
97
257
|
と言うclass名の要素に 余白を作るcss指示を反映させたい
|
98
258
|
|
99
259
|
|
100
260
|
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
101
265
|
###### 備考
|
102
266
|
|
103
267
|
|
104
268
|
|
105
|
-
|
269
|
+
javascript不要かもしれませんが念のため
|
106
|
-
|
107
|
-
あくまで仮で入ってます。
|