Reputation: 55
Good Evening everyone, im somehow stuck on a simple Problem, but just can't figuere out how to solve it. Im playing around the first time with jquery.
Now on mousenter it plays the audiofile just fine, but i tried to implement a on mouseout function to stop the audio file from playing. I simple can't get it to work.
I hope someone can help me out that would be great :)
<div class="buttonmit2ani">
<audio id="beep-one" preload="auto">
<source src="audio/baby.mp3"></source>
<source src="audio/beep.ogg"></source>
Your browser isn't invited for super fun time.
</audio>
<script>
var beepOne = $("#beep-one")[0];
$(".buttonmit2ani")
.mouseenter(function() {
beepOne.play();
);
</script>
</div>
Upvotes: 2
Views: 600
Reputation: 26878
There isn't a .stop()
function (at least not in Chrome). Use .pause()
var beepOne = $("#beep-one")[0];
$(".buttonmit2ani").mouseenter(function() {
beepOne.play();
}).mouseleave(function() {
beepOne.pause();
});
.buttonmit2ani {
width: 100px;
height: 100px;
background-color: #E9EAEE;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="buttonmit2ani">
<audio id="beep-one" preload="auto">
<source src="audio/acdc.ogg">
Your browser is not invited for super fun time.
</audio>
</div>
Upvotes: 0
Reputation: 500
Try This:
var beepOne = $("#beep-one")[0];
$('.buttonmit2ani').mouseover(function(){
beepOne.play();
}).mouseout(function(){
beepOne.stop(); // need to write this method or .pause()
});
Upvotes: 1