質問編集履歴
2
修正。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,303 +1,3 @@
|
|
1
|
-
```css
|
2
|
-
|
3
|
-
@charset "UTF-8";
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
h1{
|
8
|
-
|
9
|
-
font-family: 'Sacramento', cursive;
|
10
|
-
|
11
|
-
color:#4ea8f9;
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
body{
|
20
|
-
|
21
|
-
text-align: center;
|
22
|
-
|
23
|
-
background: #000022;
|
24
|
-
|
25
|
-
}
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
.appframe{
|
30
|
-
|
31
|
-
background: #ffffff;
|
32
|
-
|
33
|
-
width: 420px;
|
34
|
-
|
35
|
-
margin: auto;
|
36
|
-
|
37
|
-
padding: 10px;
|
38
|
-
|
39
|
-
border-radius: 10px;
|
40
|
-
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
ul{
|
46
|
-
|
47
|
-
list-style: none;
|
48
|
-
|
49
|
-
padding: 0;
|
50
|
-
|
51
|
-
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
li{
|
56
|
-
|
57
|
-
border-top: solid 1px #b1daff;
|
58
|
-
|
59
|
-
padding: 2px;
|
60
|
-
|
61
|
-
cursor: pointer;
|
62
|
-
|
63
|
-
font-family: 'Noto Sans JP', sans-serif;
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
.active{
|
70
|
-
|
71
|
-
background: #efefff;
|
72
|
-
|
73
|
-
color:#00CB98;
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
li:hover{
|
80
|
-
|
81
|
-
background: #efefff;
|
82
|
-
|
83
|
-
}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
i{
|
88
|
-
|
89
|
-
font-family: "Font Awesome 5 Free";
|
90
|
-
|
91
|
-
font-weight: 900;
|
92
|
-
|
93
|
-
content: "\f007";
|
94
|
-
|
95
|
-
color:#00FFBF;
|
96
|
-
|
97
|
-
font-size: 1.3em
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
p{
|
106
|
-
|
107
|
-
font-family: 'Sacramento', cursive;
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
```
|
112
|
-
|
113
|
-
```HTML
|
114
|
-
|
115
|
-
<!DOCTYPE html>
|
116
|
-
|
117
|
-
<html1>
|
118
|
-
|
119
|
-
<head>
|
120
|
-
|
121
|
-
<meta charset="utf-8">
|
122
|
-
|
123
|
-
<title>MusicPlayer</title>
|
124
|
-
|
125
|
-
<link rel="stylesheet" href="mplayer.css">
|
126
|
-
|
127
|
-
<link href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" rel="stylesheet">
|
128
|
-
|
129
|
-
</head>
|
130
|
-
|
131
|
-
<body>
|
132
|
-
|
133
|
-
<div class="appframe">
|
134
|
-
|
135
|
-
<h1>MusicPlayer</h1>
|
136
|
-
|
137
|
-
<img src = "pict_stop.png" alt="再生状態を表す画像">
|
138
|
-
|
139
|
-
<audio src="流れるように.mp3" controls></audio>
|
140
|
-
|
141
|
-
<p>Choose the song♫<a id="random" href="#" style="text-decoration:none;"> <i class="fad fa-random"></i></a></p>
|
142
|
-
|
143
|
-
<ul>
|
144
|
-
|
145
|
-
<li data-file="流れるように.mp3" class="active">流れるように</li>
|
146
|
-
|
147
|
-
<li data-file="なぞなぞタイム.mp3">なぞなぞタイム</li>
|
148
|
-
|
149
|
-
<li data-file="ざつだんちゅう.mp3">ざつだんちゅう</li>
|
150
|
-
|
151
|
-
<li data-file="Morning.mp3">Morning</li>
|
152
|
-
|
153
|
-
<li data-file="野良猫は宇宙を目指した.mp3">野良猫は宇宙を目指した</li>
|
154
|
-
|
155
|
-
<li data-file="なんでしょう?.mp3">なんでしょう?</li>
|
156
|
-
|
157
|
-
</ul>
|
158
|
-
|
159
|
-
<script src="mplayer.js" charset="utf-8"></script>
|
160
|
-
|
161
|
-
</div>
|
162
|
-
|
163
|
-
</body>
|
164
|
-
|
165
|
-
</html1>
|
166
|
-
|
167
|
-
```
|
168
|
-
|
169
|
-
```JavaScript
|
170
|
-
|
171
|
-
var listitems = document.querySelectorAll('li');
|
172
|
-
|
173
|
-
for (var i=0; i<listitems.length; i++){
|
174
|
-
|
175
|
-
listitems[i].addEventListener('click',
|
176
|
-
|
177
|
-
(e)=>{
|
178
|
-
|
179
|
-
var li = e.target;
|
180
|
-
|
181
|
-
playMusic(li);
|
182
|
-
|
183
|
-
}
|
184
|
-
|
185
|
-
);
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
function playMusic(li){
|
192
|
-
|
193
|
-
var file = li.getAttribute('data-file');
|
194
|
-
|
195
|
-
var audio = document.querySelector('audio');
|
196
|
-
|
197
|
-
audio.setAttribute('src', file);
|
198
|
-
|
199
|
-
audio.play();
|
200
|
-
|
201
|
-
//activeな項目を変更
|
202
|
-
|
203
|
-
var activeli = document.querySelector('.active');
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
activeli.className = '';
|
208
|
-
|
209
|
-
li.className = 'active';
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
//再生中と停止中でイラストを変える
|
216
|
-
|
217
|
-
var audio = document.querySelector('audio');
|
218
|
-
|
219
|
-
audio.addEventListener('play',
|
220
|
-
|
221
|
-
(e)=>{
|
222
|
-
|
223
|
-
var img = document.querySelector('img');
|
224
|
-
|
225
|
-
img.setAttribute('src', 'pict_play.png');
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
);
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
audio.addEventListener('pause',
|
234
|
-
|
235
|
-
(e)=>{
|
236
|
-
|
237
|
-
var img = document.querySelector('img');
|
238
|
-
|
239
|
-
img.setAttribute('src', 'pict_stop.png');
|
240
|
-
|
241
|
-
}
|
242
|
-
|
243
|
-
);
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
audio.addEventListener('ended',
|
248
|
-
|
249
|
-
(e)=>{
|
250
|
-
|
251
|
-
var img = document.querySelector('img');
|
252
|
-
|
253
|
-
img.setAttribute('src', 'pict_stop.png');
|
254
|
-
|
255
|
-
//次の曲に切り替え
|
256
|
-
|
257
|
-
var activeli = document.querySelector('.active');
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
var nextli = activeli.nextElementSibling;
|
262
|
-
|
263
|
-
if(nextli != null){
|
264
|
-
|
265
|
-
playMusic(nextli);
|
266
|
-
|
267
|
-
}
|
268
|
-
|
269
|
-
}
|
270
|
-
|
271
|
-
);
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
//ランダム選曲機能
|
276
|
-
|
277
|
-
var random = document.querySelector('#random');
|
278
|
-
|
279
|
-
random.addEventListener('click',
|
280
|
-
|
281
|
-
(e)=>{
|
282
|
-
|
283
|
-
e.preventDefault();
|
284
|
-
|
285
|
-
var listitems = document.querySelectorAll('li');
|
286
|
-
|
287
|
-
var len = listitems.length;
|
288
|
-
|
289
|
-
var rnd = Math.floor(Math.random() * len);
|
290
|
-
|
291
|
-
playMusic(listitems[rnd]);
|
292
|
-
|
293
|
-
}
|
294
|
-
|
295
|
-
);
|
296
|
-
|
297
|
-
```
|
298
|
-
|
299
|
-
|
300
|
-
|
301
1
|
ジャバスクリプトとHTMLとCSSで簡単なミュージックプレイヤーを作っています。
|
302
2
|
|
303
3
|
最後の曲が終わったら、最初の曲に戻るように設定したいのですがどうすればいいでしょうか。
|
1
コードを追加しました。よろしくお願いします。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,35 +1,303 @@
|
|
1
|
+
```css
|
2
|
+
|
3
|
+
@charset "UTF-8";
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
h1{
|
8
|
+
|
9
|
+
font-family: 'Sacramento', cursive;
|
10
|
+
|
11
|
+
color:#4ea8f9;
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
}
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
body{
|
20
|
+
|
21
|
+
text-align: center;
|
22
|
+
|
23
|
+
background: #000022;
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
.appframe{
|
30
|
+
|
31
|
+
background: #ffffff;
|
32
|
+
|
33
|
+
width: 420px;
|
34
|
+
|
35
|
+
margin: auto;
|
36
|
+
|
37
|
+
padding: 10px;
|
38
|
+
|
39
|
+
border-radius: 10px;
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
ul{
|
46
|
+
|
47
|
+
list-style: none;
|
48
|
+
|
49
|
+
padding: 0;
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
li{
|
56
|
+
|
57
|
+
border-top: solid 1px #b1daff;
|
58
|
+
|
59
|
+
padding: 2px;
|
60
|
+
|
61
|
+
cursor: pointer;
|
62
|
+
|
63
|
+
font-family: 'Noto Sans JP', sans-serif;
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
.active{
|
70
|
+
|
71
|
+
background: #efefff;
|
72
|
+
|
73
|
+
color:#00CB98;
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
li:hover{
|
80
|
+
|
81
|
+
background: #efefff;
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
i{
|
88
|
+
|
89
|
+
font-family: "Font Awesome 5 Free";
|
90
|
+
|
91
|
+
font-weight: 900;
|
92
|
+
|
93
|
+
content: "\f007";
|
94
|
+
|
95
|
+
color:#00FFBF;
|
96
|
+
|
97
|
+
font-size: 1.3em
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
p{
|
106
|
+
|
107
|
+
font-family: 'Sacramento', cursive;
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
```HTML
|
114
|
+
|
115
|
+
<!DOCTYPE html>
|
116
|
+
|
117
|
+
<html1>
|
118
|
+
|
119
|
+
<head>
|
120
|
+
|
121
|
+
<meta charset="utf-8">
|
122
|
+
|
123
|
+
<title>MusicPlayer</title>
|
124
|
+
|
125
|
+
<link rel="stylesheet" href="mplayer.css">
|
126
|
+
|
127
|
+
<link href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" rel="stylesheet">
|
128
|
+
|
129
|
+
</head>
|
130
|
+
|
131
|
+
<body>
|
132
|
+
|
133
|
+
<div class="appframe">
|
134
|
+
|
135
|
+
<h1>MusicPlayer</h1>
|
136
|
+
|
137
|
+
<img src = "pict_stop.png" alt="再生状態を表す画像">
|
138
|
+
|
139
|
+
<audio src="流れるように.mp3" controls></audio>
|
140
|
+
|
141
|
+
<p>Choose the song♫<a id="random" href="#" style="text-decoration:none;"> <i class="fad fa-random"></i></a></p>
|
142
|
+
|
143
|
+
<ul>
|
144
|
+
|
145
|
+
<li data-file="流れるように.mp3" class="active">流れるように</li>
|
146
|
+
|
147
|
+
<li data-file="なぞなぞタイム.mp3">なぞなぞタイム</li>
|
148
|
+
|
149
|
+
<li data-file="ざつだんちゅう.mp3">ざつだんちゅう</li>
|
150
|
+
|
151
|
+
<li data-file="Morning.mp3">Morning</li>
|
152
|
+
|
153
|
+
<li data-file="野良猫は宇宙を目指した.mp3">野良猫は宇宙を目指した</li>
|
154
|
+
|
155
|
+
<li data-file="なんでしょう?.mp3">なんでしょう?</li>
|
156
|
+
|
157
|
+
</ul>
|
158
|
+
|
159
|
+
<script src="mplayer.js" charset="utf-8"></script>
|
160
|
+
|
161
|
+
</div>
|
162
|
+
|
163
|
+
</body>
|
164
|
+
|
165
|
+
</html1>
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
```JavaScript
|
170
|
+
|
171
|
+
var listitems = document.querySelectorAll('li');
|
172
|
+
|
173
|
+
for (var i=0; i<listitems.length; i++){
|
174
|
+
|
175
|
+
listitems[i].addEventListener('click',
|
176
|
+
|
177
|
+
(e)=>{
|
178
|
+
|
179
|
+
var li = e.target;
|
180
|
+
|
181
|
+
playMusic(li);
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
);
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
function playMusic(li){
|
192
|
+
|
193
|
+
var file = li.getAttribute('data-file');
|
194
|
+
|
195
|
+
var audio = document.querySelector('audio');
|
196
|
+
|
197
|
+
audio.setAttribute('src', file);
|
198
|
+
|
199
|
+
audio.play();
|
200
|
+
|
201
|
+
//activeな項目を変更
|
202
|
+
|
203
|
+
var activeli = document.querySelector('.active');
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
activeli.className = '';
|
208
|
+
|
209
|
+
li.className = 'active';
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
//再生中と停止中でイラストを変える
|
216
|
+
|
217
|
+
var audio = document.querySelector('audio');
|
218
|
+
|
219
|
+
audio.addEventListener('play',
|
220
|
+
|
221
|
+
(e)=>{
|
222
|
+
|
223
|
+
var img = document.querySelector('img');
|
224
|
+
|
225
|
+
img.setAttribute('src', 'pict_play.png');
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
);
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
audio.addEventListener('pause',
|
234
|
+
|
235
|
+
(e)=>{
|
236
|
+
|
237
|
+
var img = document.querySelector('img');
|
238
|
+
|
239
|
+
img.setAttribute('src', 'pict_stop.png');
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
);
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
audio.addEventListener('ended',
|
248
|
+
|
249
|
+
(e)=>{
|
250
|
+
|
251
|
+
var img = document.querySelector('img');
|
252
|
+
|
253
|
+
img.setAttribute('src', 'pict_stop.png');
|
254
|
+
|
255
|
+
//次の曲に切り替え
|
256
|
+
|
257
|
+
var activeli = document.querySelector('.active');
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
var nextli = activeli.nextElementSibling;
|
262
|
+
|
263
|
+
if(nextli != null){
|
264
|
+
|
265
|
+
playMusic(nextli);
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
);
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
//ランダム選曲機能
|
276
|
+
|
277
|
+
var random = document.querySelector('#random');
|
278
|
+
|
279
|
+
random.addEventListener('click',
|
280
|
+
|
281
|
+
(e)=>{
|
282
|
+
|
283
|
+
e.preventDefault();
|
284
|
+
|
285
|
+
var listitems = document.querySelectorAll('li');
|
286
|
+
|
287
|
+
var len = listitems.length;
|
288
|
+
|
289
|
+
var rnd = Math.floor(Math.random() * len);
|
290
|
+
|
291
|
+
playMusic(listitems[rnd]);
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
);
|
296
|
+
|
297
|
+
```
|
298
|
+
|
299
|
+
|
300
|
+
|
1
301
|
ジャバスクリプトとHTMLとCSSで簡単なミュージックプレイヤーを作っています。
|
2
302
|
|
3
303
|
最後の曲が終わったら、最初の曲に戻るように設定したいのですがどうすればいいでしょうか。
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
JavaScriptのファイル
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
audio.addEventListener('ended',
|
12
|
-
|
13
|
-
(e)=>{
|
14
|
-
|
15
|
-
var img = document.querySelector('img');
|
16
|
-
|
17
|
-
img.setAttribute('src', 'pict_stop.png');
|
18
|
-
|
19
|
-
//次の曲に切り替え
|
20
|
-
|
21
|
-
var activeli = document.querySelector('.active');
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
var nextli = activeli.nextElementSibling;
|
26
|
-
|
27
|
-
if(nextli != null){
|
28
|
-
|
29
|
-
playMusic(nextli);
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
}
|
34
|
-
|
35
|
-
);
|