-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
121 lines (103 loc) · 3.87 KB
/
Copy pathscript.js
File metadata and controls
121 lines (103 loc) · 3.87 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
// Wait until the entire HTML document is loaded before running the script
document.addEventListener('DOMContentLoaded', () => {
// --- DOM Element Selection ---
const loaderOverlay = document.getElementById('loader-overlay');
const enterButton = document.getElementById('enter-button');
const mainContent = document.getElementById('main-content');
const audioControls = document.getElementById('audio-controls');
const socialLinks = document.getElementById('social-links');
const audio = document.getElementById('background-audio');
const playPauseButton = document.getElementById('play-pause-button');
const canvas = document.getElementById('dynamic-background');
const ctx = canvas.getContext('2d');
let animationFrameId;
// --- Enter Site Logic ---
enterButton.addEventListener('click', () => {
// Fade out the loader
loaderOverlay.style.opacity = '0';
// Wait for fade out to complete before hiding it
setTimeout(() => {
loaderOverlay.style.display = 'none';
}, 500);
// Fade in the main content and controls
mainContent.classList.remove('hidden');
audioControls.classList.remove('hidden');
socialLinks.classList.remove('hidden');
// Start audio and update button
audio.play().catch(error => console.log("Audio autoplay was prevented. User must interact first."));
playPauseButton.textContent = 'Pause';
// Start the background animation
startAnimation();
});
// --- Audio Controls Logic ---
playPauseButton.addEventListener('click', () => {
if (audio.paused) {
audio.play();
playPauseButton.textContent = 'Pause';
} else {
audio.pause();
playPauseButton.textContent = 'Play';
}
});
// --- Dynamic Background Animation ---
let particlesArray;
// Set canvas size to full window size
function setCanvasSize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
setCanvasSize();
// Particle object
class Particle {
constructor() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.size = Math.random() * 2 + 1;
this.speedX = Math.random() * 1 - 0.5;
this.speedY = Math.random() * 1 - 0.5;
}
update() {
this.x += this.speedX;
this.y += this.speedY;
// Reset particle position if it goes off-screen
if (this.x > canvas.width || this.x < 0) this.x = Math.random() * canvas.width;
if (this.y > canvas.height || this.y < 0) this.y = Math.random() * canvas.height;
}
draw() {
ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
// Create and initialize particles
function init() {
particlesArray = [];
let numberOfParticles = (canvas.height * canvas.width) / 9000;
for (let i = 0; i < numberOfParticles; i++) {
particlesArray.push(new Particle());
}
}
// Animation loop
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < particlesArray.length; i++) {
particlesArray[i].update();
particlesArray[i].draw();
}
animationFrameId = requestAnimationFrame(animate);
}
function startAnimation() {
init();
animate();
}
function stopAnimation() {
cancelAnimationFrame(animationFrameId);
}
// Adjust canvas and particle count on window resize
window.addEventListener('resize', () => {
stopAnimation();
setCanvasSize();
startAnimation();
});
});