Created
December 12, 2013 15:01
-
-
Save chrislawes/7929370 to your computer and use it in GitHub Desktop.
Fade in HTML5 Audio tag (jQuery)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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