Javascript: Example: using Javascript to create sound buttons, Javascript tutorial
Introduction:
In general, buttons on a webpage do not trigger sound events. If you want the button to respond to the sound of the mouse action, you can write a JavaScript script code.
The script that can make the button sound. You don't need to make the Flash button. I feel pretty good when trying it out.
Production method:
1. Create a file:
The following is a reference clip: DynamicAudioButton. js, code: // Customize Dynamic Audio Link custom Dynamic sound Link Function DynamicAudioLink (){ Open ("http://www.pcedu.com.cn ") }
// Customize Dynamic Audio Mouse Over Color custom Dynamic sound mouseover Color Function AudioOver (){ Document. Audio. button. style. background = "#999999" Document. Audio. button. style. color = "white" }
// Customize Dynamic Audio Mouse Down Color custom Dynamic sound mousedown Color Function AudioDown (){ Document. Audio. button. style. color = "# cccccc" }
// Customize Dynamic Audio Mouse Off Color custom Dynamic sound mouseOff Color Function AudioOut (){ Document. Audio. button. style. background = "#666666" Document. Audio. button. style. color = "# ffffff" }
// Customize Dynamic Audio sound custom Dynamic sound Function playHome () { Document. all. sound. src = "bleep.wav "; }
Document. write (' ') // Customize Button Style Custom Button Style Document. write (' '+' '+'') Document. write (' ') |
2. After saving the file, insert the code in the relevant part of the page to reference the JS file:
The following is a reference clip: Script |
3. Select a music file, such as wav and MP3, which should be as small as possible.
After the method is created, you can use images and other forms. Of course, you must modify the corresponding code of the DynamicAudioButton. js file.