Reputation: 15
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.in-middle {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.button {
border-radius: 50%;
background-color: red;
color: white;
}
</style>
</head>
<body>
<div class="in-middle">
<button class="button">
click me
</button>
</div>
</body>
</html>
Basically, i have this code for a button. How do i add a function that starts playing music with the controller hidden, and sends you to next page while still playing the music?
Upvotes: 0
Views: 38
Reputation: 690
you have to audio source first then assign a function on the button
<audio id="myAudio">
<source src="horse.ogg" type="audio/ogg">
</audio>
<div id="controler">
</div>
<div class="in-middle">
<button class="button" onclick="myfunction">
click me
</button>
</div>
then add the function on the js file
function myfunction(){
document.getElementById("myAudio").play(); //it will start the audio
document.getElementById("controler").style.display="none" // it will hide your controller
window.location.href="pageurl"; // this will open new window
}
Upvotes: 1