質問編集履歴
2
HTML/CSS/JSのソースコードを追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,10 +14,176 @@
|
|
14
14
|
何度シャッフルしてもクリックして色が変わるようにしたいのですが上手くいきません。
|
15
15
|
|
16
16
|
### 該当のソースコード
|
17
|
+
長くなってしまいますが全コードを追記させていただきました。
|
17
18
|
|
19
|
+
```HTML
|
20
|
+
<body>
|
21
|
+
<table>
|
22
|
+
<thead>
|
23
|
+
<tr><th>B</th><th>I</th><th>N</th><th>G</th><th>O</th></tr>
|
18
|
-
|
24
|
+
</thead>
|
25
|
+
<tbody>
|
26
|
+
|
27
|
+
</tbody>
|
28
|
+
</table>
|
19
29
|
|
30
|
+
<div id="refresh">カードをシャッフル</div>
|
31
|
+
|
32
|
+
<div id="lock">カードを決定する</div>
|
33
|
+
|
34
|
+
<script src="js/main.js">
|
35
|
+
</script>
|
36
|
+
</body>
|
37
|
+
```
|
38
|
+
|
39
|
+
```CSS
|
40
|
+
body {
|
41
|
+
font-family: 'Courier New' , monospace;
|
42
|
+
user-select: none;
|
43
|
+
}
|
44
|
+
|
45
|
+
table {
|
46
|
+
margin: 15px auto;
|
47
|
+
}
|
48
|
+
|
49
|
+
th, td {
|
50
|
+
width: 60px;
|
51
|
+
height: 60px;
|
52
|
+
text-align: center;
|
53
|
+
line-height: 60px;
|
54
|
+
}
|
55
|
+
th {
|
56
|
+
font-size: 24px;
|
57
|
+
font-weight: bold;
|
58
|
+
}
|
59
|
+
td {
|
60
|
+
background-color: orange;
|
61
|
+
border: 2px solid orange;
|
62
|
+
border-radius: 5px;
|
63
|
+
cursor: pointer;
|
64
|
+
transition: 0.5s;
|
65
|
+
}
|
66
|
+
|
67
|
+
.opened {
|
68
|
+
background-color: white;
|
69
|
+
border-radius: 50%;
|
70
|
+
transform: rotateX(360deg);
|
71
|
+
}
|
72
|
+
|
73
|
+
#refresh {
|
74
|
+
height: 40px;
|
75
|
+
width: 200px;
|
76
|
+
background-color: lightsalmon;
|
77
|
+
border-radius: 10px;
|
78
|
+
box-shadow: 0 5px salmon;
|
79
|
+
margin: 40px auto;
|
80
|
+
text-align: center;
|
81
|
+
line-height: 40px;
|
82
|
+
cursor: pointer;
|
83
|
+
user-select: none;
|
84
|
+
}
|
85
|
+
#refresh:hover {
|
86
|
+
opacity: 0.8;
|
87
|
+
}
|
88
|
+
#refresh:active {
|
89
|
+
transform: translate(0, 5px);
|
90
|
+
box-shadow: none;
|
91
|
+
opacity: 1;
|
92
|
+
}
|
93
|
+
|
94
|
+
#lock {
|
95
|
+
height: 40px;
|
96
|
+
width: 200px;
|
97
|
+
background-color: lightgreen;
|
98
|
+
border-radius: 10px;
|
99
|
+
margin: 20px auto;
|
100
|
+
text-align: center;
|
101
|
+
line-height: 40px;
|
102
|
+
cursor: pointer;
|
103
|
+
user-select: none;
|
104
|
+
}
|
105
|
+
|
106
|
+
.inactive {
|
107
|
+
opacity: 0.5 !important;
|
108
|
+
background-color: #777 !important;
|
109
|
+
box-shadow: 0 5px #444 !important;
|
110
|
+
pointer-events: none !important;
|
111
|
+
}
|
112
|
+
|
113
|
+
.active {
|
114
|
+
background-color: green !important;
|
115
|
+
}
|
116
|
+
```
|
117
|
+
|
20
118
|
```JavaScript
|
119
|
+
'use strict';
|
120
|
+
|
121
|
+
{
|
122
|
+
function createColumn(col) {
|
123
|
+
const source = [];
|
124
|
+
for (let i = 0; i < 15; i++){
|
125
|
+
source[i] = i + 1 + 15 * col;
|
126
|
+
}
|
127
|
+
|
128
|
+
const column = [];
|
129
|
+
for (let i = 0; i < 5; i++){
|
130
|
+
column[i] = source.splice (Math.floor(Math.random() * source.length), 1)[0];
|
131
|
+
}
|
132
|
+
|
133
|
+
return column;
|
134
|
+
}
|
135
|
+
|
136
|
+
function createColumns(){
|
137
|
+
const columns = [];
|
138
|
+
for (let i = 0; i < 5; i++){
|
139
|
+
columns[i] = createColumn(i);
|
140
|
+
}
|
141
|
+
|
142
|
+
columns[2][2] = 'FREE';
|
143
|
+
return columns;
|
144
|
+
}
|
145
|
+
|
146
|
+
function renderBingo(columns){
|
147
|
+
const tbody = document.querySelector('tbody')
|
148
|
+
|
149
|
+
while(tbody.firstChild) {
|
150
|
+
tbody.removeChild(tbody.firstChild);
|
151
|
+
}
|
152
|
+
|
153
|
+
for (let row = 0; row < 5; row++){
|
154
|
+
const tr = document.createElement('tr');
|
155
|
+
for (let col = 0; col < 5; col++){
|
156
|
+
const td = document.createElement('td');
|
157
|
+
td.textContent = columns[col][row];
|
158
|
+
tr.appendChild(td);
|
159
|
+
}
|
160
|
+
document.querySelector('tbody').appendChild(tr);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
const columns = createColumns();
|
165
|
+
renderBingo(columns);
|
166
|
+
|
167
|
+
|
168
|
+
const refresh = document.getElementById('refresh');
|
169
|
+
const lock = document.getElementById('lock');
|
170
|
+
|
171
|
+
refresh.addEventListener('click', () => {
|
172
|
+
const columns = createColumns();
|
173
|
+
renderBingo(columns);
|
174
|
+
});
|
175
|
+
|
176
|
+
lock.addEventListener('click', () => {
|
177
|
+
refresh.classList.toggle('inactive');
|
178
|
+
lock.classList.toggle('active');
|
179
|
+
if(lock.classList.contains('active') === true){
|
180
|
+
lock.textContent = 'カードを変更する';
|
181
|
+
}else{
|
182
|
+
lock.textContent = 'カードを決定する';
|
183
|
+
}
|
184
|
+
|
185
|
+
});
|
186
|
+
|
21
187
|
const td = document.querySelectorAll('td');
|
22
188
|
|
23
189
|
for (let i = 0; i < 25; i++) {
|
@@ -25,6 +191,7 @@
|
|
25
191
|
td[i].classList.toggle('opened');
|
26
192
|
});
|
27
193
|
}
|
194
|
+
}
|
28
195
|
```
|
29
196
|
|
30
197
|
### 試したこと
|
1
初心者マークを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -34,4 +34,4 @@
|
|
34
34
|
|
35
35
|
###
|
36
36
|
|
37
|
-
プログラミング学習を初めて2ヶ月ほどの初心者で無知ではありますが、よろしくお願い
|
37
|
+
プログラミング学習を初めて2ヶ月ほどの初心者で無知ではありますが、よろしくお願い致します。
|