Is it possible to use HTML5 to make a sound when a user hovers over one of my list item buttons? I'd like to play a very short click/chirp sound one time when a user hovers over a navigation button. I realize it won't be compatible on every browser or device and that's OK as long as it degrades gracefully. Would it be better to use Flash for this for some reason?
Edit
Also, if it's possible to do this I'd be interested in some sample code, including the javascript (if javascript is needed). I'm OK with HTML but not too handy with Javascript.
You can use any audio. Then a global constant of buttons is set. Then the sound in the 'audio' is linked to the button by the onclick event. Then I have used the play () method here to play the audio.
Hello everyone, In this post, we will examine how to solve the How You Can Use Javascript To Play The Sound For The Button Color Selected problem using the computer language. var audio = new Audio("play. mp3"); audio. play();
HTML Audio - How It WorksThe controls attribute adds audio controls, like play, pause, and volume. The <source> element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format.
I’ve not done anything like this, but it should be possible. E.g.
<audio id="myaudio" src="myaudio.mp3"></audio>
<button onmouseover="document.getElementById('myaudio').play()">Hover me</button>
I’m not familiar with Flash, so I’m not sure if you can use JavaScript to get a Flash file to play.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With