Skip to content

Instantly share code, notes, and snippets.

@albach
Created April 25, 2018 12:57
Show Gist options
  • Save albach/33f878acce557f69a778d65db6ca889e to your computer and use it in GitHub Desktop.
Save albach/33f878acce557f69a778d65db6ca889e to your computer and use it in GitHub Desktop.
<!-- === HTML AUDIO -->
<audio id="cAudio">
<source src="../static/media/c_note.mp3" type="audio/mpeg"></source>
<source src="../static/media/c_note.ogg" type="audio/ogg"></source>
<source src="../static/media/c_note.wav" type="audio/wav"></source>
</audio>
<a id="c" href="">Click me!</a>
<script type="text/javascript">
// === JS AUDIO
// This controls the button for the c note.
// This variable calls the cNote audio element in the HTML.
var cNote = document.getElementById('cAudio');
// This turns our <div id= "c"> into a button that plays our audio file when the box is pressed.
$('#c').on("mousedown", function(){
// This is a property that scrubs the audio file back to its start.
cNote.currentTime = 0;
// This plays the audio file.
cNote.play();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment