Categories:

Home / Free JavaScripts / Images & Music / Here

Cut & Paste onMouseover/onClick sound effect

Credit: FPMC

Description: This is what you've been waiting for...a script that plays a sound when the mouse moves over certain links. It can be configured to initiate the sound only when someone clicks on the links as well (see footnote). The script works in BOTH NS and IE (in NS, the LiveAudio plugin must exist). Thanks to FPMC, a helpful visitor and friend here at JavaScript Kit, for the creation.

Example: Move your mouse over any of the links below to hear a sound effect!

Point.gif (101 bytes) CNN

Point.gif (101 bytes) ABC News

Point.gif (101 bytes) CBS News

Point.gif (101 bytes) MSNBC

Point.gif (101 bytes) BBC News

Directions:

Step 1: Add the following to the <head> section of your page:

Step 2: Edit the aySound array to preload the sound files.

aySound[0]="YourSoundFile.wav";
aySound[1]="AnotherSoundFile.wav";
aySound[2]="EvenAnotherOne.wav";
.
.

as many sound files as one wants.

Important! Please make sure the sound files exist, or else errors will occur.

Step 3: Finally, play the sound files with an event handler.

- onMouseOver/onMouseOut sound:
   <A HREF="YourPage.html" onMouseOver="playSound(0)" onMouseOut="stopSound(0)">Move mouse over to play sound</A>

- onClick sound:
   <A HREF="javascript:playSound(0);">Click here to play sound</A>

-
   <INPUT TYPE="BUTTON" VALUE="Click me!" onClick="playSound(0)">

Note: playSound(0) plays the audio file of aySound[0]; playSound(1) will play aySound[1], etc.


JavaScript Tools:
Site Info

CopyRight © 1998-2010 JavaScript Kit. NO PART may be reproduced without author's permission.