23 lines
623 B
JavaScript
23 lines
623 B
JavaScript
function get_audio(music_box) {
|
|
return music_box.querySelector('audio');
|
|
}
|
|
|
|
const music_boxes = document.getElementsByClassName('music-box');
|
|
for (const music_box of music_boxes) {
|
|
music_box.addEventListener('click', () => {
|
|
const audio = get_audio(music_box);
|
|
if (audio.paused) {
|
|
// pause all other music boxes
|
|
for (const music_box of music_boxes) {
|
|
music_box.classList.remove('playing');
|
|
get_audio(music_box).pause();
|
|
}
|
|
music_box.classList.add('playing');
|
|
audio.play();
|
|
} else {
|
|
music_box.classList.remove('playing');
|
|
audio.pause();
|
|
}
|
|
});
|
|
}
|