質問編集履歴
1
全体のコードを載せました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -23,3 +23,555 @@
|
|
23
23
|
すると1回目は思ったようになるのですが、なぜか2回以上タイプミスをすると白いままになってしまいます。
|
24
24
|
|
25
25
|
よろしくお願いいたします。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```html
|
30
|
+
|
31
|
+
<!DOCTYPE html>
|
32
|
+
|
33
|
+
<html>
|
34
|
+
|
35
|
+
<head>
|
36
|
+
|
37
|
+
<meta charset="utf-8">
|
38
|
+
|
39
|
+
<link rel="stylesheet" type="text/css" href="./reset.css">
|
40
|
+
|
41
|
+
<link rel="stylesheet" type="text/css" href="./main.css">
|
42
|
+
|
43
|
+
<!-- <link rel="stylesheet" type="text/js" href="js/index.js"> -->
|
44
|
+
|
45
|
+
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css"> -->
|
46
|
+
|
47
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
48
|
+
|
49
|
+
<script src="./main.js"></script>
|
50
|
+
|
51
|
+
<title>Let's Typing!</title>
|
52
|
+
|
53
|
+
</head>
|
54
|
+
|
55
|
+
<body>
|
56
|
+
|
57
|
+
<div class="background">
|
58
|
+
|
59
|
+
<div class="question"></div>
|
60
|
+
|
61
|
+
<div class="keyboard">
|
62
|
+
|
63
|
+
<ul class="line0">
|
64
|
+
|
65
|
+
<li class="49 key1">1</li>
|
66
|
+
|
67
|
+
<li class="50">2</li>
|
68
|
+
|
69
|
+
<li class="51">3</li>
|
70
|
+
|
71
|
+
<li class="52">4</li>
|
72
|
+
|
73
|
+
<li class="53">5</li>
|
74
|
+
|
75
|
+
<li class="54">6</li>
|
76
|
+
|
77
|
+
<li class="55">7</li>
|
78
|
+
|
79
|
+
<li class="56">8</li>
|
80
|
+
|
81
|
+
<li class="57">9</li>
|
82
|
+
|
83
|
+
<li class="58">0</li>
|
84
|
+
|
85
|
+
<li class="189">-</li>
|
86
|
+
|
87
|
+
<li class="222">^</li>
|
88
|
+
|
89
|
+
<li class="220">¥</li>
|
90
|
+
|
91
|
+
<li class="8 backspace">Back<br>space</li>
|
92
|
+
|
93
|
+
</ul>
|
94
|
+
|
95
|
+
<ul class="line1">
|
96
|
+
|
97
|
+
<li class="9 tab">Tab</li>
|
98
|
+
|
99
|
+
<li class="81 q">Q</li>
|
100
|
+
|
101
|
+
<li class="87 w">W</li>
|
102
|
+
|
103
|
+
<li class="69 e">E</li>
|
104
|
+
|
105
|
+
<li class="82 r">R</li>
|
106
|
+
|
107
|
+
<li class="84 t">T</li>
|
108
|
+
|
109
|
+
<li class="89 y">Y</li>
|
110
|
+
|
111
|
+
<li class="85 u">U</li>
|
112
|
+
|
113
|
+
<li class="73 i">I</li>
|
114
|
+
|
115
|
+
<li class="79 o">O</li>
|
116
|
+
|
117
|
+
<li class="80 p">P</li>
|
118
|
+
|
119
|
+
<li class="192 @">@</li>
|
120
|
+
|
121
|
+
<li class="219 [">[</li>
|
122
|
+
|
123
|
+
<li class="13 enter">Enter</li>
|
124
|
+
|
125
|
+
</ul>
|
126
|
+
|
127
|
+
<ul class="line2">
|
128
|
+
|
129
|
+
<li class="17 control">Control</li>
|
130
|
+
|
131
|
+
<li class="65 a">A</li>
|
132
|
+
|
133
|
+
<li class="83 s">S</li>
|
134
|
+
|
135
|
+
<li class="68 d">D</li>
|
136
|
+
|
137
|
+
<li class="70 f">F</li>
|
138
|
+
|
139
|
+
<li class="71 g">G</li>
|
140
|
+
|
141
|
+
<li class="72 h">H</li>
|
142
|
+
|
143
|
+
<li class="74 j">J</li>
|
144
|
+
|
145
|
+
<li class="75 k">K</li>
|
146
|
+
|
147
|
+
<li class="76 l">L</li>
|
148
|
+
|
149
|
+
<li class="187">;</li>
|
150
|
+
|
151
|
+
<li class="186">:</li>
|
152
|
+
|
153
|
+
<li class="221">]</li>
|
154
|
+
|
155
|
+
</ul>
|
156
|
+
|
157
|
+
<ul class="line3">
|
158
|
+
|
159
|
+
<li class="16 shift">Shift </li>
|
160
|
+
|
161
|
+
<li class="90 z">Z</li>
|
162
|
+
|
163
|
+
<li class="88 x">X</li>
|
164
|
+
|
165
|
+
<li class="67 c">C</li>
|
166
|
+
|
167
|
+
<li class="86 v">V</li>
|
168
|
+
|
169
|
+
<li class="66 b">B</li>
|
170
|
+
|
171
|
+
<li class="78 n">N</li>
|
172
|
+
|
173
|
+
<li class="77 m">M</li>
|
174
|
+
|
175
|
+
<li class="188">,</li>
|
176
|
+
|
177
|
+
<li class="190">.</li>
|
178
|
+
|
179
|
+
<li class="191">/</li>
|
180
|
+
|
181
|
+
<li class="226">_</li>
|
182
|
+
|
183
|
+
<li class="16 shift">Shift </li>
|
184
|
+
|
185
|
+
</ul>
|
186
|
+
|
187
|
+
<ul class="line4">
|
188
|
+
|
189
|
+
<li class="capslock">Capslock</li>
|
190
|
+
|
191
|
+
<li class="option">option</li>
|
192
|
+
|
193
|
+
<li class="command">command</li>
|
194
|
+
|
195
|
+
<li class="selectKey">英数</li>
|
196
|
+
|
197
|
+
<li class="space">Space</li>
|
198
|
+
|
199
|
+
<li class="selectKey">かな</li>
|
200
|
+
|
201
|
+
<li class="command">command</li>
|
202
|
+
|
203
|
+
<li class="">fn</li>
|
204
|
+
|
205
|
+
<li class="37 selectKey">◀︎</li>
|
206
|
+
|
207
|
+
<li class="nonBorder"><div class="38 selectKey">▲</div><div class="40 selectKey">▼</div></li>
|
208
|
+
|
209
|
+
<li class="39 selectKey">▶︎</li>
|
210
|
+
|
211
|
+
</ul>
|
212
|
+
|
213
|
+
</div>
|
214
|
+
|
215
|
+
</div>
|
216
|
+
|
217
|
+
</body>
|
218
|
+
|
219
|
+
</html>
|
220
|
+
|
221
|
+
```
|
222
|
+
|
223
|
+
```css
|
224
|
+
|
225
|
+
*{
|
226
|
+
|
227
|
+
box-sizing: border-box;
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
body{
|
234
|
+
|
235
|
+
background-color: rgb(206, 198, 198);
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
.question{
|
242
|
+
|
243
|
+
color: rgb(61, 43, 43);
|
244
|
+
|
245
|
+
text-align: center;
|
246
|
+
|
247
|
+
font-size: 75px;
|
248
|
+
|
249
|
+
font-weight: 600;
|
250
|
+
|
251
|
+
padding: 50px;
|
252
|
+
|
253
|
+
margin-bottom: 40px;
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
.question span:nth-child(1){
|
260
|
+
|
261
|
+
color: red;
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
.keyboard ul{
|
268
|
+
|
269
|
+
list-style: none;
|
270
|
+
|
271
|
+
margin: 0 auto;
|
272
|
+
|
273
|
+
text-align: center;
|
274
|
+
|
275
|
+
height: 50px;
|
276
|
+
|
277
|
+
width: 900px;
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
.keyboard li, .keyboard .selectKey{
|
284
|
+
|
285
|
+
color: rgb(209, 144, 144);
|
286
|
+
|
287
|
+
font-size: 25px;
|
288
|
+
|
289
|
+
display: inline-block;
|
290
|
+
|
291
|
+
border-radius: 10% 10%;
|
292
|
+
|
293
|
+
min-width: 50px; /* */
|
294
|
+
|
295
|
+
font-weight: 550;
|
296
|
+
|
297
|
+
height: 50px; /* */
|
298
|
+
|
299
|
+
vertical-align: top;
|
300
|
+
|
301
|
+
line-height: 50px; /* */
|
302
|
+
|
303
|
+
background-color: rgb(61, 43, 43);
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
.keyboard .backspace,.keyboard .tab,.keyboard .control,.keyboard .shift,.keyboard .capslock,.keyboard .option,.keyboard .command,.keyboard .space,.keyboard .enter{
|
310
|
+
|
311
|
+
letter-spacing: -2px;
|
312
|
+
|
313
|
+
font-size: 14px; /* */
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
.keyboard .backspace{
|
320
|
+
|
321
|
+
line-height: 22.5px; /* */
|
322
|
+
|
323
|
+
padding: 2px; /* */
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
.keyboard .nonBorder{
|
330
|
+
|
331
|
+
height: 50px; /* */
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
.selectKey{
|
338
|
+
|
339
|
+
line-height: 25px; /* */
|
340
|
+
|
341
|
+
height: 25px; /* */
|
342
|
+
|
343
|
+
display: block;
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
.keyboard .selectKey{
|
350
|
+
|
351
|
+
width: 60px;
|
352
|
+
|
353
|
+
font-size: 20px;
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
.keyboard .enter{
|
358
|
+
|
359
|
+
height: 116px;
|
360
|
+
|
361
|
+
width: 53px;
|
362
|
+
|
363
|
+
margin-left: 24px;
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
.line0{
|
370
|
+
|
371
|
+
padding-left: 1px;
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
.line2{
|
378
|
+
|
379
|
+
padding-right: 57px;
|
380
|
+
|
381
|
+
}
|
382
|
+
|
383
|
+
.line3{
|
384
|
+
|
385
|
+
padding-left: 4px;
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
.line4{
|
390
|
+
|
391
|
+
padding-right: 3px;
|
392
|
+
|
393
|
+
}
|
394
|
+
|
395
|
+
.keyboard .key1{
|
396
|
+
|
397
|
+
width: 76px;
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
.keyboard .control{
|
402
|
+
|
403
|
+
width: 76px;
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
.keyboard .shift{
|
408
|
+
|
409
|
+
width: 92px;
|
410
|
+
|
411
|
+
}
|
412
|
+
|
413
|
+
.keyboard .capslock,.keyboard .command{
|
414
|
+
|
415
|
+
width: 69px;
|
416
|
+
|
417
|
+
}
|
418
|
+
|
419
|
+
.keyboard .space{
|
420
|
+
|
421
|
+
width: 139px;
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
/* ハート基本 */
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
.heart {
|
432
|
+
|
433
|
+
width: 50px;
|
434
|
+
|
435
|
+
height: 45px;
|
436
|
+
|
437
|
+
position: relative;
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
.heart::before,
|
442
|
+
|
443
|
+
.heart::after {
|
444
|
+
|
445
|
+
position: absolute;
|
446
|
+
|
447
|
+
content: "";
|
448
|
+
|
449
|
+
left: 25px;
|
450
|
+
|
451
|
+
top: 3px;
|
452
|
+
|
453
|
+
width: 28px;
|
454
|
+
|
455
|
+
height: 45px;
|
456
|
+
|
457
|
+
background: red;
|
458
|
+
|
459
|
+
border-radius: 50% 50% 0 0/31.3% 31.3% 0 0;
|
460
|
+
|
461
|
+
transform: rotate(-45deg);
|
462
|
+
|
463
|
+
transform-origin: 0 100%;
|
464
|
+
|
465
|
+
z-index: -10;
|
466
|
+
|
467
|
+
}
|
468
|
+
|
469
|
+
.heart::after {
|
470
|
+
|
471
|
+
left: -3px;
|
472
|
+
|
473
|
+
background: red;
|
474
|
+
|
475
|
+
transform: rotate(45deg);
|
476
|
+
|
477
|
+
transform-origin :100% 100%;
|
478
|
+
|
479
|
+
}
|
480
|
+
|
481
|
+
```
|
482
|
+
|
483
|
+
```jquery
|
484
|
+
|
485
|
+
$(function () {
|
486
|
+
|
487
|
+
let questions = new Array("hello", "goodbye", "yes", "no");
|
488
|
+
|
489
|
+
function selectQuestion() {
|
490
|
+
|
491
|
+
let question = '';
|
492
|
+
|
493
|
+
let randnum = Math.floor(Math.random() * 3);
|
494
|
+
|
495
|
+
questions[randnum].split('').forEach(function (c) {
|
496
|
+
|
497
|
+
question += '<span>'+c+'</span>';
|
498
|
+
|
499
|
+
});
|
500
|
+
|
501
|
+
$('.question').html(question);
|
502
|
+
|
503
|
+
return randnum;
|
504
|
+
|
505
|
+
};
|
506
|
+
|
507
|
+
function setKey() {
|
508
|
+
|
509
|
+
$(".keyboard ." + questions[qNumber][chrNumber-1]).html('<div class="heart">' + charactor + '</div>'); // ブラウザのキーボードに今問題の文字にhtmlを挿入する
|
510
|
+
|
511
|
+
$(".keyboard ." + questions[qNumber][chrNumber-1]).children().css({ color: 'white', height: '50px', lineHeight: '46px' }); //色等をつける
|
512
|
+
|
513
|
+
$(".keyboard ." + questions[qNumber][chrNumber-1]).css('background-color', 'transparent'); //元の色を消す
|
514
|
+
|
515
|
+
};
|
516
|
+
|
517
|
+
let chrNumber = 1; // 問題の言葉の何文字目か
|
518
|
+
|
519
|
+
let qNumber = selectQuestion(); // 配列の何個目の言葉か(ランダムで選ばれた)
|
520
|
+
|
521
|
+
let charactor = $(".keyboard ." + questions[qNumber][0]).text();
|
522
|
+
|
523
|
+
setKey();
|
524
|
+
|
525
|
+
$(window).keydown(function (e) {
|
526
|
+
|
527
|
+
console.log(e.keyCode);
|
528
|
+
|
529
|
+
if ($('.question span:nth-child(' + chrNumber + ')').text() == String.fromCharCode(e.keyCode).toLowerCase()) {
|
530
|
+
|
531
|
+
// 色を戻す
|
532
|
+
|
533
|
+
$('.question span:nth-child(' + chrNumber + ')').css('color', 'rgb(61, 43, 43)');
|
534
|
+
|
535
|
+
$(".keyboard ." + String.fromCharCode(e.keyCode).toLowerCase()).html(String.fromCharCode(e.keyCode)).css({ color: 'rgb(209, 144, 144)', backgroundColor: 'rgb(61, 43, 43)' });
|
536
|
+
|
537
|
+
if (chrNumber < questions[qNumber].length) {
|
538
|
+
|
539
|
+
chrNumber += 1;
|
540
|
+
|
541
|
+
charactor = $(".keyboard ." + questions[qNumber][chrNumber - 1]).text();
|
542
|
+
|
543
|
+
// 色を変える
|
544
|
+
|
545
|
+
$('.question span:nth-child(' + chrNumber + ')').css('color', 'red');
|
546
|
+
|
547
|
+
setKey();
|
548
|
+
|
549
|
+
} else {
|
550
|
+
|
551
|
+
chrNumber = 1;
|
552
|
+
|
553
|
+
qNumber = selectQuestion();
|
554
|
+
|
555
|
+
charactor = $(".keyboard ." + questions[qNumber][0]).text();
|
556
|
+
|
557
|
+
setKey();
|
558
|
+
|
559
|
+
}
|
560
|
+
|
561
|
+
} else {
|
562
|
+
|
563
|
+
$('body').css('background-color', 'white');
|
564
|
+
|
565
|
+
$('body').delay(100).queue(function () {
|
566
|
+
|
567
|
+
$(this).css('background-color', 'rgb(206, 198, 198)');
|
568
|
+
|
569
|
+
});
|
570
|
+
|
571
|
+
}
|
572
|
+
|
573
|
+
})
|
574
|
+
|
575
|
+
})
|
576
|
+
|
577
|
+
```
|