ccdp10003-project01/main.js

31 lines
762 B
JavaScript
Raw Normal View History

2023-04-18 01:40:26 +10:00
const backgroundAudio = document.getElementById("backgroundAudio");
2023-04-18 03:33:53 +10:00
const playPauseButton = document.getElementById("playPause")
let audioPlaying = false
2023-04-18 01:40:26 +10:00
2023-04-18 03:33:53 +10:00
const playPauseAudio = () => {
if (audioPlaying === true) {
playPauseButton.innerHTML = playPauseButton.innerHTML.replace('pause', 'play');
backgroundAudio.pause();
audioPlaying = false;
} else {
playPauseButton.innerHTML = playPauseButton.innerHTML.replace('play', 'pause');
backgroundAudio.play();
audioPlaying = true;
}
2023-04-18 01:40:26 +10:00
};
const stopAudio = () => {
backgroundAudio.currentTime = 0;
2023-04-18 03:33:53 +10:00
audioPlaying = true;
playPauseAudio();
};
const begin = () => {
// First pause the audio
playPauseAudio();
// Then fade everything out
// Finally, load in the new content
2023-04-18 01:40:26 +10:00
};