Button Hover Sound using HTML5 Audio

11,000

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.

Share:
11,000
HK1
Author by

HK1

Program Contractor and Manager MS Access, VBA, ADO, SQL Server, MySQL, ASP Classic, ADO.NET, C#, VB.NET, WPF, PHP, Javascript, AngularJS, ASP.NET, ASP.NET MVC, ASP.NET Web API, HTML, CSS, JSON, Android/JAVA, Arduino/C

Updated on June 20, 2022

Comments

  • HK1
    HK1 about 2 years

    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.

  • nzifnab
    nzifnab over 13 years
    Flash can interact with javascript and vice versa - but for this it's not really necessary.
  • Joe Dargie
    Joe Dargie about 11 years
    "it doesn't need HTML5" - but it does, presumably, need QuickTime, Windows Media Player, or Real Player.
  • Camilo Martin
    Camilo Martin about 11 years
    @PaulD.Waite Yeah, this was in '11 when IE6/7/8 was more of an annoyance. Today I'd also recommend HTML5 for audio needs, and some fallback that works fine in IE8. Also, I believe Windows and Mac at least are covered with QuickTime and Windows Media Player.