I've managed to successfully trigger the audio to play on hover, but I'm having trouble getting it to pause when my mouse leaves the area.
Check out the code in action here: https://jsfiddle.net/jzhang172/nLm9bxnw/1/
$(document).ready(function(){
var audio = $("#audio-1")[0];
$(".box").hover
(function() {
audio.play();
},
(function(){
audio.stop();
});
});
.box{
height:500px;
width:500px;
display:flex;
justify-content:center;
align-items:center;
font-size:25px;
color:white;
background:black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<audio controls id="audio-1">
<source src="http://www.stephaniequinn.com/Music/Allegro%20from%20Duet%20in%20C%20Major.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div class="box">
If you Hover me, the song will play!
</div>