add volume slider

This commit is contained in:
zyl 2024-11-04 10:30:57 -08:00
parent 8572827797
commit c688fe4347
Signed by: zyl
SSH key fingerprint: SHA256:uxxbSXbdroP/OnKBGnEDk5q7EKB2razvstC/KmzdXXs
2 changed files with 12 additions and 0 deletions

View file

@ -26,6 +26,9 @@
<p> <p>
<label>one in <input type="number" min="0" value="10" id="random-chance"> chance of playing every minute</label> <label>one in <input type="number" min="0" value="10" id="random-chance"> chance of playing every minute</label>
</p> </p>
<p>
<label><input type="range" id="volume" min="0" max="100" value="100"> volume</label>
</p>
</body> </body>
</html> </html>

View file

@ -7,6 +7,7 @@
const now = document.getElementById("play-now"); const now = document.getElementById("play-now");
const playAtRandom = document.getElementById("play-at-random"); const playAtRandom = document.getElementById("play-at-random");
const randomChance = document.getElementById("random-chance"); const randomChance = document.getElementById("random-chance");
const volume = document.getElementById("volume");
playAtRandom.checked = false; playAtRandom.checked = false;
@ -43,6 +44,13 @@
pipe.addEventListener("click", play); pipe.addEventListener("click", play);
} }
volume.addEventListener("input", () => {
const v = volume.value / 100;
if (v >= 0 && v <= 1) {
pipefall.volume = v;
}
});
function random(max) { function random(max) {
return Math.floor(Math.random() * max); return Math.floor(Math.random() * max);
} }
@ -63,4 +71,5 @@
} }
}, 1000); }, 1000);
updateFalls(); updateFalls();
pipefall.volume = volume.value / 100;
})(); })();