Skip to content

Instantly share code, notes, and snippets.

@chrislawes
Created December 12, 2013 15:01
Show Gist options
  • Save chrislawes/7929370 to your computer and use it in GitHub Desktop.
Save chrislawes/7929370 to your computer and use it in GitHub Desktop.
Fade in HTML5 Audio tag (jQuery)
var backgroundVolume = 0; // start background volume at 0
$('#main_audio')[0].volume = backgroundVolume; // set volume to 0
$('#main_audio')[0].play(); // start playing tag
var fadeInAudio = setInterval(
function() {
if(backgroundVolume <= 1) // if it's not at 1 (full volume)
{
$('#main_audio')[0].volume = backgroundVolume; // set new volume
backgroundVolume += 0.1;
}
else
{
clearInterval(fadeInAudio); // if at full volume, stop adding to it
}
}, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment