Cut & Paste onMouseover/onClick sound effect
|
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!
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.
