-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
172 lines (156 loc) · 6.25 KB
/
Copy pathscript.js
File metadata and controls
172 lines (156 loc) · 6.25 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
document.addEventListener('DOMContentLoaded', () => {
const body = document.body;
let particles = [];
let numberOfConfettiPerBatch = 5;
let creationIntervalTime = 100;
let maxParticles = 200;
body.style.background = '#000';
const appleLogoImages = [
'apple-red.png',
'apple-orange.png',
'apple-yellow.png',
'apple-green.png',
'apple-blue.png',
'apple-turquoise.png',
'apple-pink.png',
'apple-purple.png',
'apple-gray.png',
'apple-white.png'
];
const screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
const smallScreenWidthThreshold = 345;
const audioElement = new Audio("audio.mp3");
let isPlaying = false;
audioElement.autoplay = true;
audioElement.loop = false;
audioElement.mute = false;
body.appendChild(audioElement);
function handleFirstInteraction() {
audioElement.muted = false;
audioElement.play().catch(error => {
console.error("Audio play failed after interaction:", error);
});
document.removeEventListener('click', handleFirstInteraction);
document.removeEventListener('touchstart', handleFirstInteraction);
}
// Add event listeners for the first user interaction
document.addEventListener('click', handleFirstInteraction);
document.addEventListener('touchstart', handleFirstInteraction);
const mainTitle = document.createElement('h1');
mainTitle.textContent = "WWDC26";
mainTitle.id = 'mainTitle';
mainTitle.style.position = 'fixed';
mainTitle.style.display = 'block';
mainTitle.style.top = '30%';
mainTitle.style.left = '50%';
mainTitle.style.width = '100%';
mainTitle.style.textAlign = 'center';
mainTitle.style.transform = 'translate(-50%, -50%)';
mainTitle.style.fontFamily = 'Arial';
mainTitle.style.color = 'white';
mainTitle.style.fontSize = '3em';
body.appendChild(mainTitle);
const secondaryText = document.createElement('p');
secondaryText.textContent = "Jun. 8 - 12";
secondaryText.id = 'mainTitle';
secondaryText.style.position = 'fixed';
secondaryText.style.display = 'block';
secondaryText.style.top = '36%';
secondaryText.style.left = '50%';
secondaryText.style.width = '100%';
secondaryText.style.textAlign = 'center';
secondaryText.style.transform = 'translate(-50%, -50%)';
secondaryText.style.fontFamily = 'Arial';
secondaryText.style.color = 'white';
secondaryText.style.fontSize = '1.5em';
body.appendChild(secondaryText);
const footerText = document.createElement('footer');
footerText.textContent = "♫ Start Up - A. J. Cook ♫";
footerText.style.position = 'fixed';
footerText.style.top = '97%';
footerText.style.textAlign = 'center';
footerText.style.right = '10px';
footerText.style.fontFamily = 'Arial';
footerText.style.color = '#ddd';
body.appendChild(footerText);
footerText.addEventListener('touchstart', () => {
if (isPlaying) {
audioElement.pause();
footerText.textContent = 'Play Music';
} else {
audioElement.play().catch(error => {
console.error("Failed to Play Music:", error);
footerText.textContent = 'Play Failed';
});
footerText.textContent = 'Pause Music';
}
isPlaying = !isPlaying;
});
if (screenWidth < smallScreenWidthThreshold) {
numberOfConfettiPerBatch = 2;
maxParticles = 50;
mainTitle.style.left = '50%';
mainTitle.style.fontSize = '1.5em';
secondaryText.style.top = '37%';
secondaryText.style.fontSize = '0.9em';
footerText.style.top = '75%';
}
function createConfettiBatch(count) {
const titleElement = document.getElementById('mainTitle');
const titleZIndex = titleElement ? parseInt(titleElement.style.zIndex) || 0 : 0;
for (let i = 0; i < count; i++) {
if (particles.length >= maxParticles) {
return;
}
const img = document.createElement('img');
const horizontalStart = Math.random() * (window.innerWidth + 200) - 100;
img.src = appleLogoImages[Math.floor(Math.random() * appleLogoImages.length)];
img.classList.add('confetti-particle');
img.style.width = `100px`;
img.style.height = `100px`;
img.style.left = `${horizontalStart}px`;
img.style.top = `${-200 - Math.random() * 150}px`;
img.style.transform = `rotate(${Math.random() * 360}deg)`;
img.style.position = 'fixed';
body.appendChild(img);
const randomNumber = Math.random();
if (randomNumber < 0.5) {
img.style.zIndex = titleZIndex - 1;
} else if (randomNumber < 0.7) {
img.style.zIndex = titleZIndex;
} else {
img.style.zIndex = titleZIndex + 1;
}
particles.push({
element: img,
speed: Math.random() * 5 + 5,
rotationSpeed: (Math.random() - 0.9) * 5,
drift: (Math.random() - 0.9) * 2
});
}
}
function updateConfetti() {
particles.forEach((particle, index) => {
const currentTop = parseFloat(particle.element.style.top) || -200;
particle.element.style.top = `${currentTop + particle.speed}px`;
particle.currentRotation = (particle.currentRotation || 0) + particle.rotationSpeed;
particle.element.style.transform = `rotate(${particle.currentRotation}deg)`;
if (currentTop > window.innerHeight + 5) {
particle.element.remove();
particles.splice(index, 1);
}
});
requestAnimationFrame(updateConfetti);
}
function startConfetti() {
setInterval(() => {
createConfettiBatch(numberOfConfettiPerBatch);
}, creationIntervalTime);
updateConfetti();
}
startConfetti();
const titleElement = document.getElementById('mainTitle');
if (titleElement) {
titleElement.style.zIndex = '-1';
}
});