Audio fadeouts/fadeins?

I'm really new to javascript. I can load audio in a passage using the html audio tag but I can't figure out how to implement audio fade outs and fade ins.

Is there any option for this.?


I did manage to make a small bit of code that works with the html audio tag to control audio fade outs the only problem is that it requires the function to be pasted in each and every section it is used in even when it is used in a master section. Squiffy for some strange cannot access a function or a variable if it exists in another section. Either way the code works, but it's a clunky implementation in my opinion.

    function fadeOut(mySound){
    var myAudio = document.getElementById(mySound);
    if(myAudio.volume > 0.005){
    myAudio.volume -= 0.005;
    setTimeout(function(){fadeOut(mySound);},20);
    }
    else{ myAudio.pause();
    }
    }
    fadeOut("Audio");    

Can't you just add the Javascript function to the main index HTML template, and then call via individual sections?

That's how I usually manage sound.


This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums