-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.js
More file actions
245 lines (190 loc) · 6.06 KB
/
java.js
File metadata and controls
245 lines (190 loc) · 6.06 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// Developed with GitHub Copilot assistance, code from line 37 to line 156 creates interactive audio players with animated voice waveform visualizations
document.addEventListener('DOMContentLoaded', function() {
const introScreen = document.getElementById('startpage');
const mainContent = document.getElementById('content');
const startupSound = document.getElementById('startupSound');
if (!introScreen || !mainContent) return;
introScreen.addEventListener("click", () => {
if (startupSound) {
startupSound.volume = 0.3;
startupSound.currentTime = 0;
startupSound.play().catch(() => {
console.log('Startup sound could not be played - user interaction may be required');
});
}
introScreen.classList.add("fadeout");
setTimeout(() => {
introScreen.classList.add("hidden");
mainContent.classList.remove("hidden");
}, 1000);
});
const audioPlayer = document.getElementById('audioPlayer');
const playButton = document.getElementById('playButton');
const visualizer = document.getElementById('visualizer');
let isPlaying = false;
let animationId;
function createVisualizer() {
for (let i = 0; i < 50; i++) {
const bar = document.createElement('div');
bar.className = 'bar';
bar.style.height = '10px';
visualizer.appendChild(bar);
}
}
function togglePlay() {
if (isPlaying) {
audioPlayer.pause();
playButton.textContent = '▶';
isPlaying = false;
stopAnimation();
} else {
audioPlayer.play().catch(() => {});
playButton.textContent = '⏸';
isPlaying = true;
startAnimation();
}
}
function animate() {
if (!isPlaying) return;
const bars = visualizer.querySelectorAll('.bar');
bars.forEach((bar, index) => {
const height = Math.random() * 60 + 20;
bar.style.height = height + 'px';
});
animationId = requestAnimationFrame(animate);
}
function startAnimation() {
animate();
}
function stopAnimation() {
cancelAnimationFrame(animationId);
visualizer.querySelectorAll('.bar').forEach(bar => {
bar.style.height = '10px';
});
}
audioPlayer.addEventListener('ended', () => {
playButton.textContent = '▶';
isPlaying = false;
stopAnimation();
});
createVisualizer();
playButton.addEventListener('click', togglePlay);
const audioPlayer2 = document.getElementById('audioPlayer2');
const playButton2 = document.getElementById('playButton2');
const visualizer2 = document.getElementById('visualizer2');
let isPlaying2 = false;
let animationId2;
function createVisualizer2() {
for (let i = 0; i < 50; i++) {
const bar = document.createElement('div');
bar.className = 'bar';
bar.style.height = '10px';
visualizer2.appendChild(bar);
}
}
function togglePlay2() {
if (isPlaying2) {
audioPlayer2.pause();
playButton2.textContent = '▶';
isPlaying2 = false;
stopAnimation2();
} else {
audioPlayer2.play().catch(() => {});
playButton2.textContent = '⏸';
isPlaying2 = true;
startAnimation2();
}
}
function animate2() {
if (!isPlaying2) return;
const bars = visualizer2.querySelectorAll('.bar');
bars.forEach((bar, index) => {
const height = Math.random() * 60 + 20;
bar.style.height = height + 'px';
});
animationId2 = requestAnimationFrame(animate2);
}
function startAnimation2() {
animate2();
}
function stopAnimation2() {
cancelAnimationFrame(animationId2);
visualizer2.querySelectorAll('.bar').forEach(bar => {
bar.style.height = '10px';
});
}
audioPlayer2.addEventListener('ended', () => {
playButton2.textContent = '▶';
isPlaying2 = false;
stopAnimation2();
});
createVisualizer2();
playButton2.addEventListener('click', togglePlay2);
});
function toggleContent(contentId) {
const content = document.getElementById(contentId);
const icon = content.previousElementSibling.querySelector('.toggleicon');
if (content.classList.contains('expanded')) {
content.classList.remove('expanded');
icon.classList.remove('rotated');
} else {
content.classList.add('expanded');
icon.classList.add('rotated');
}
}
function goToSection(sectionId) {
const startPage = document.getElementById('startpage');
const content = document.getElementById('content');
const startupSound = document.getElementById('startupSound');
if (startPage && !startPage.classList.contains('hidden')) {
if (startupSound) {
startupSound.volume = 0.3;
startupSound.currentTime = 0;
startupSound.play().catch(() => {
console.log('Startup sound could not be played - user interaction may be required');
});
}
startPage.classList.add("fadeout");
setTimeout(() => {
startPage.classList.add("hidden");
content.classList.remove("hidden");
setTimeout(() => {
document.getElementById(sectionId).scrollIntoView({
behavior: 'smooth'
});
}, 100);
}, 1000);
} else {
document.getElementById(sectionId).scrollIntoView({
behavior: 'smooth'
});
}
return false;
}
document.addEventListener('DOMContentLoaded', function() {
const video = document.querySelector('.roundedvideo');
const overlay = document.getElementById('videoOverlay');
if (!video || !overlay) return;
video.addEventListener('play', function() {
overlay.classList.add('active');
video.classList.add('playing');
});
video.addEventListener('pause', function() {
overlay.classList.remove('active');
video.classList.remove('playing');
});
video.addEventListener('ended', function() {
overlay.classList.remove('active');
video.classList.remove('playing');
});
overlay.addEventListener('click', function(e) {
if (e.target === overlay) {
video.pause();
}
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && overlay.classList.contains('active')) {
video.pause();
}
});
});