How can I fade out an audio element using vanilla js (no jquery)? I have looked at the numerous other questions on this forum but they all seem overly complicated or use jquery. I have written this code below. However, I get the following error: "Uncaught DOMException: Failed to set the 'volume' property on 'HTMLMediaElement': The volume provided (-7.52870e-16) is outside the range [0, 1]."
viewer.on('mouseup', function(event) {
var mouseDownSound = document.getElementById("mouseDownSound");
mouseDownSound.volume = 1;
var vol = mouseDownSound.volume;
function fadeOut() {
setInterval(
function() {
if (vol > 0) {
vol -= 0.01;
mouseDownSound.volume = vol;
}
else {
clearInterval(fadeOut);
}
}, 2);
}
fadeOut();
});