Kumi
b2ec8b62cb
Ensure audio tracks loop continuously to improve user experience by maintaining audio ambiance without interruption. This change prevents abrupt stops when audio files reach their end, enhancing the seamlessness of sound playbacks.
57 lines
No EOL
1.5 KiB
JavaScript
57 lines
No EOL
1.5 KiB
JavaScript
const audioFiles = {
|
|
rain: new Audio('audio/rain.mp3'),
|
|
};
|
|
|
|
for (const audio in audioFiles) {
|
|
audioFiles[audio].loop = true;
|
|
}
|
|
|
|
function toggleSound() {
|
|
if (!playing) {
|
|
for (const audio in audioFiles) {
|
|
audioFiles[audio].play();
|
|
playing = true;
|
|
}
|
|
}
|
|
else {
|
|
for (const audio in audioFiles) {
|
|
audioFiles[audio].pause();
|
|
playing = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
document.getElementById('toggle').addEventListener('click', toggleSound);
|
|
|
|
const sliders = document.getElementsByClassName('sound-slider');
|
|
|
|
Array.from(sliders).forEach(slider => {
|
|
slider.addEventListener('input', function (e) {
|
|
for (const audio in audioFiles) {
|
|
const slider = document.getElementById(audio + '-slider');
|
|
audioFiles[audio].volume = slider.value / 100;
|
|
}
|
|
})
|
|
});
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const modal = document.getElementById('attribution-modal');
|
|
const openButton = document.getElementById('attributions-button');
|
|
const closeButton = modal.querySelector('.close-button');
|
|
|
|
openButton.addEventListener('click', () => {
|
|
modal.style.display = 'block';
|
|
});
|
|
|
|
closeButton.addEventListener('click', () => {
|
|
modal.style.display = 'none';
|
|
});
|
|
|
|
window.addEventListener('click', (event) => {
|
|
if (event.target === modal) {
|
|
modal.style.display = 'none';
|
|
}
|
|
});
|
|
});
|
|
|
|
var playing = false; |