質問するログイン新規登録

質問編集履歴

2

どのような方針ですすめていけばよいかだけでもアドバイスいただければと思います

2023/08/28 00:25

投稿

inoyu
inoyu

スコア1

title CHANGED
File without changes
body CHANGED
@@ -129,4 +129,13 @@
129
129
  ### 試したこと
130
130
  クリックする度に増える変数を宣言してみたり、ifの条件式を考えてみましたが、どう書けばうまく動作するのかわかりませんでした、、、
131
131
 
132
+ ↓追記
132
133
 
134
+ let count = 0 ;
135
+ lists.forEach((li) => {
136
+ li.addEventListener("click", () => {
137
+ li[count].classList.add("pressed");
138
+ count++;
139
+ });
140
+ });
141
+

1

cssを追加しました

2023/08/28 00:08

投稿

inoyu
inoyu

スコア1

title CHANGED
File without changes
body CHANGED
@@ -20,6 +20,74 @@
20
20
  <div id="btn">スタート</div>
21
21
  </div>
22
22
  ```
23
+ ```css
24
+ body {
25
+ background: #ccc;
26
+ color: #fff;
27
+ font-family: 'Courier New', sans-serif;
28
+ font-size: 16px;
29
+ font-weight: bold;
30
+ }
31
+
32
+ #container {
33
+ /* 50px * 2 + 10px * 2 */
34
+ width: 120px;
35
+ margin: 16px auto;
36
+ }
37
+
38
+ #board {
39
+ display: flex;
40
+ flex-wrap: wrap;
41
+ list-style: none;
42
+ margin: 0 0 8px;
43
+ padding: 10px;
44
+ background: #fff;
45
+ border-radius: 4px;
46
+ }
47
+
48
+ #board li {
49
+ background: #00aaff;
50
+ width: 40px;
51
+ height: 40px;
52
+ margin: 5px;
53
+ cursor: pointer;
54
+ border-radius: 4px;
55
+ line-height: 40px;
56
+ text-align: center;
57
+ box-shadow: 0 4px 0 #0088cc;
58
+ }
59
+
60
+ #board li.pressed{
61
+ background: #ccc;
62
+ box-shadow: none;
63
+ margin-top: 9px;
64
+ margin-bottom: 1px;
65
+ }
66
+
67
+
68
+ #timer {
69
+ margin-bottom: 8px;
70
+ font-size: 20px;
71
+ text-align: right;
72
+ }
73
+
74
+ #btn {
75
+ cursor: pointer;
76
+ user-select: none;
77
+ background: #f44336;
78
+ padding: 8px;
79
+ border-radius: 4px;
80
+ text-align: center;
81
+ box-shadow: 0 4px 0 #d1483e;
82
+ }
83
+
84
+ #btn:active {
85
+ margin-top: 12px;
86
+ box-shadow: none;
87
+ }
88
+
89
+ ```
90
+
23
91
  ```javascript
24
92
  const btn = document.querySelector("#btn");
25
93
  const lists = [...document.querySelectorAll("li")];