-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
96 lines (86 loc) · 2.74 KB
/
script.js
File metadata and controls
96 lines (86 loc) · 2.74 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
let currentPage = 1;
const totalPages = 12;
const progressBar = document.getElementById('progress-bar');
const progressFill = document.getElementById('progress-fill');
const backgroundMusic = document.getElementById('background-music');
const playMusicButton = document.getElementById('play-music-button');
const pauseMusicButton = document.getElementById('pause-music-button');
const volumeControl = document.getElementById('volume-control');
function nextPage() {
const current = document.getElementById(`page-${currentPage}`);
current.classList.add('hidden');
currentPage++;
if (currentPage > totalPages) {
currentPage = 1; // Loop back to the start
}
const next = document.getElementById(`page-${currentPage}`);
next.classList.remove('hidden');
updateProgress();
}
function restartStory() {
currentPage = 1;
document.querySelectorAll('.page').forEach(page => page.classList.add('hidden'));
document.getElementById(`page-${currentPage}`).classList.remove('hidden');
updateProgress();
}
function updateProgress() {
const progress = (currentPage / totalPages) * 100;
progressFill.style.width = `${progress}%`;
}
function toggleMusic() {
if (backgroundMusic.paused) {
backgroundMusic.play();
playMusicButton.style.display = 'none';
pauseMusicButton.style.display = 'inline-block';
} else {
backgroundMusic.pause();
playMusicButton.style.display = 'inline-block';
pauseMusicButton.style.display = 'none';
}
}
volumeControl.addEventListener('input', (event) => {
backgroundMusic.volume = event.target.value;
});
function makeChoice(choice) {
switch(choice) {
case 'choice1':
showPage(3);
break;
case 'choice2':
showPage(4);
break;
case 'choice3':
showPage(5);
break;
case 'choice4':
showPage(6);
break;
case 'choice5':
showPage(7);
break;
case 'choice6':
showPage(8);
break;
case 'choice7':
showPage(9);
break;
case 'choice8':
showPage(10);
break;
case 'choice9':
showPage(11);
break;
case 'choice10':
showPage(12);
break;
default:
restartStory();
break;
}
}
function showPage(pageNumber) {
document.querySelectorAll('.page').forEach(page => page.classList.add('hidden'));
document.getElementById(`page-${pageNumber}`).classList.remove('hidden');
currentPage = pageNumber;
updateProgress();
}