回答編集履歴
2
蛇足追加
test
CHANGED
@@ -47,3 +47,237 @@
|
|
47
47
|
|
48
48
|
|
49
49
|
```
|
50
|
+
|
51
|
+
蛇足も追加
|
52
|
+
|
53
|
+
```javascript
|
54
|
+
|
55
|
+
<html lang="ja">
|
56
|
+
|
57
|
+
<meta charset="utf-8">
|
58
|
+
|
59
|
+
<title>sample</title>
|
60
|
+
|
61
|
+
<style>
|
62
|
+
|
63
|
+
main{
|
64
|
+
|
65
|
+
position: relative;
|
66
|
+
|
67
|
+
overflow: hidden;
|
68
|
+
|
69
|
+
background: #f6f5f5;
|
70
|
+
|
71
|
+
width: 980px;
|
72
|
+
|
73
|
+
height: 200px;
|
74
|
+
|
75
|
+
margin: auto;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
div{
|
80
|
+
|
81
|
+
font-size: 50px;
|
82
|
+
|
83
|
+
float: left;
|
84
|
+
|
85
|
+
width: 100px;
|
86
|
+
|
87
|
+
height: 100px;
|
88
|
+
|
89
|
+
background: #444;
|
90
|
+
|
91
|
+
text-align: center;
|
92
|
+
|
93
|
+
border-radius: 50px;
|
94
|
+
|
95
|
+
line-height: 90px;
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
.plus{
|
100
|
+
|
101
|
+
position: absolute;
|
102
|
+
|
103
|
+
top:50px;
|
104
|
+
|
105
|
+
left: 100px;
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
.minus{
|
110
|
+
|
111
|
+
position: absolute;
|
112
|
+
|
113
|
+
top: 50px;
|
114
|
+
|
115
|
+
right: 100px;
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
</style>
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
<body>
|
126
|
+
|
127
|
+
<h1 class="count">0</h1>
|
128
|
+
|
129
|
+
<main>
|
130
|
+
|
131
|
+
<div class="plus">+</div>
|
132
|
+
|
133
|
+
<div class="minus">-</div>
|
134
|
+
|
135
|
+
</main>
|
136
|
+
|
137
|
+
<h1 class="count">0</h1>
|
138
|
+
|
139
|
+
<main>
|
140
|
+
|
141
|
+
<div class="plus">+</div>
|
142
|
+
|
143
|
+
<div class="minus">-</div>
|
144
|
+
|
145
|
+
</main>
|
146
|
+
|
147
|
+
<h1 class="count">0</h1>
|
148
|
+
|
149
|
+
<main>
|
150
|
+
|
151
|
+
<div class="plus">+</div>
|
152
|
+
|
153
|
+
<div class="minus">-</div>
|
154
|
+
|
155
|
+
</main>
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
<script>
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
class Counter {
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
constructor (plus, minus, count, num = 0) {
|
170
|
+
|
171
|
+
this.plus = plus;
|
172
|
+
|
173
|
+
this.minus = minus;
|
174
|
+
|
175
|
+
this.count = count;
|
176
|
+
|
177
|
+
this.num = num;
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
this.disp ();
|
182
|
+
|
183
|
+
[plus, minus].forEach (e =>
|
184
|
+
|
185
|
+
e.addEventListener ('mouseover', this, false));
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
up () {
|
192
|
+
|
193
|
+
this.num += 1;
|
194
|
+
|
195
|
+
this.disp ();
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
down () {
|
202
|
+
|
203
|
+
this.num -= 1;
|
204
|
+
|
205
|
+
this.disp ();
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
disp () {
|
212
|
+
|
213
|
+
this.count.textContent = this.num;
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
handleEvent (event) {
|
220
|
+
|
221
|
+
switch (event.type) {
|
222
|
+
|
223
|
+
case 'mouseover' :
|
224
|
+
|
225
|
+
let e = event.target;
|
226
|
+
|
227
|
+
if (this.plus == e)
|
228
|
+
|
229
|
+
this.up ();
|
230
|
+
|
231
|
+
else if (this.minus == e)
|
232
|
+
|
233
|
+
this.down ();
|
234
|
+
|
235
|
+
break;
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
//___________________________________________
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
function demo () {
|
250
|
+
|
251
|
+
let
|
252
|
+
|
253
|
+
plus = document.querySelectorAll ('.plus'),
|
254
|
+
|
255
|
+
minus = document.querySelectorAll ('.minus'),
|
256
|
+
|
257
|
+
count = document.querySelectorAll ('.count');
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
Array(3).fill(0).forEach ((_,i) => {
|
262
|
+
|
263
|
+
new Counter (plus[i], minus[i], count[i]);
|
264
|
+
|
265
|
+
});
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
window.addEventListener('DOMContentLoaded', demo, false);
|
274
|
+
|
275
|
+
</script>
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
```
|
1
修正
test
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
あまりこういう書き方はお勧めしないかな?
|
2
2
|
|
3
|
+
その昔、メモリーリークパターンだって教えられたから。
|
3
4
|
|
5
|
+
(今は解決済みらしいのだけれど)
|
4
6
|
|
5
7
|
```jaascript
|
6
8
|
|