Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button Hover Sound using HTML5 Audio

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.

like image 327
HK1 Avatar asked Mar 10 '11 03:03

HK1


People also ask

How can I play sound when my button is clicked?

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.

How you can use Javascript to play the sound for the button Colour selected?

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();

How do you add sound effects in HTML?

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.


1 Answers

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.

like image 200
Paul D. Waite Avatar answered Sep 29 '22 23:09

Paul D. Waite