Sometimes we add background music to the page, allowing users to turn on and off the background music by themselves, especially multimedia pages made based on mobile html5. HTML5's audio tag can obtain the audio playback status, and the background music can be turned off and turned on by touching the button.
The renderings are as follows:
HTMLCreate an HTML5 page, place the <audio> tag, set the audio file source, and set loop playback. Prepare two pictures, indicating the two states of turning on and pausing background music, you can click.
XML/HTML Code Copy content to clipboard
When we clicked the switch image button, we called the javascript script and the playPause() function. In the function, judge the audio audio playback status. If it has been stopped (paused), call .play() to continue playing. If it is in the playback status, playback. Pause() will be immediately suspended. When switching between the two states, please see the code:
JavaScript Code Copy content to clipboard
If you use jQuery code, you can write it like this:
JavaScript Code Copy content to clipboard