-
Notifications
You must be signed in to change notification settings - Fork 0
/
invitation.js
48 lines (41 loc) · 1.73 KB
/
invitation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
document.addEventListener("DOMContentLoaded", function() {
const mainPhoto = document.getElementById('main-photo');
const backgroundMusic = document.getElementById('background-music');
const playMusicButton = document.getElementById('play-music');
const stopMusicButton = document.getElementById('stop-music');
function loadStoredSettings() {
const storedPhoto = localStorage.getItem('mainPhoto');
const storedMusicUrl = localStorage.getItem('musicUrl');
const isMusicPlaying = localStorage.getItem('musicPlaying') === 'true';
if (storedPhoto) {
mainPhoto.src = storedPhoto;
}
if (storedMusicUrl) {
backgroundMusic.src = storedMusicUrl;
if (isMusicPlaying) {
backgroundMusic.play().catch(error => {
console.error("播放背景音乐失败:", error);
});
playMusicButton.style.display = "none";
stopMusicButton.style.display = "inline";
}
}
}
function playBackgroundMusic() {
backgroundMusic.play().catch(error => {
console.error("播放背景音乐失败:", error);
});
playMusicButton.style.display = "none";
stopMusicButton.style.display = "inline";
localStorage.setItem('musicPlaying', 'true');
}
function stopBackgroundMusic() {
backgroundMusic.pause();
localStorage.setItem('musicPlaying', 'false');
playMusicButton.style.display = "inline";
stopMusicButton.style.display = "none";
}
playMusicButton.addEventListener('click', playBackgroundMusic);
stopMusicButton.addEventListener('click', stopBackgroundMusic);
loadStoredSettings();
});