The example in this article describes how jquery controls the background music switch and automatic playback of prompts. Share it with everyone for your reference. The details are as follows:
Many people add a piece of background music to the web page when they first learn to create web pages. The moment they hear the music playing, they often feel a sense of accomplishment.
Here I will explain how to use js to control the playback and stop of background music. The details are as follows:
1. jquery control background music switch
The above introduces how jquery controls the background music switch, and will be further expanded next.
2. JQuery automatically plays the prompt sound
The earliest automatic notification sound function for the website was found in the Discuz forum. But one problem is that it only supports flash and does not support HTML5. It is not clear whether the latest version supports HTML5.
For Discuz 7.2 version, player.swf, pm_1.mp3, pm_2.mp3, pm_3.mp3 are provided, and then use the following script to implement:
HTML5 open source player JPlayer supports automatic playback of prompt sounds
JPlayer supports play events to trigger automatic playback prompts.
1. Load JPlayer into a div layer, such as #jplayer.
After loading JQuery, the div content of jplayer becomes:
in browsers that support swf
becomes:
in browsers that support HTML5
After loading is completed, the playback event is triggered.
2. Trigger playback sound event
3. Loop playback function, playing a prompt tone every 5 seconds
Appendix:
1. Solve the problem that the prompt sound cannot be played automatically
If you run the playback trigger event immediately after loading JQplayer, it will have no effect! I don’t know the specific reason. It is probably because the audio file is not loaded.
2. The solution is to let the trigger event wait for 5 seconds to execute.
After the page is loaded, a prompt sound will be played automatically after 5 seconds.
I hope this article will be helpful to everyone’s jquery programming design.