Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
211 lines (171 loc) · 6.8 KB
/
Copy pathscript.js
File metadata and controls
211 lines (171 loc) · 6.8 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
/* ==========================================================================
WHAT THE FUCK CLAN - INTERACTIVE GLASS ANIMATION ENGINE
========================================================================== */
document.addEventListener("DOMContentLoaded", () => {
initInteractiveCanvas();
initGlassBubbles();
init3DTiltEffect();
initCounterAnimation();
initHeaderScrollEffect();
initMobileNav();
});
/* --------------------------------------------------------------------------
1. Interactive Canvas Glass Particle Field
-------------------------------------------------------------------------- */
function initInteractiveCanvas() {
const canvas = document.getElementById("glassParticleCanvas");
if (!canvas) return;
const ctx = canvas.getContext("2d");
let particles = [];
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener("resize", resizeCanvas);
resizeCanvas();
class Particle {
constructor() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.size = Math.random() * 2.5 + 0.5;
this.speedX = (Math.random() - 0.5) * 0.4;
this.speedY = (Math.random() - 0.5) * 0.4;
this.opacity = Math.random() * 0.5 + 0.1;
}
update() {
this.x += this.speedX;
this.y += this.speedY;
if (this.x < 0 || this.x > canvas.width) this.speedX *= -1;
if (this.y < 0 || this.y > canvas.height) this.speedY *= -1;
}
draw() {
ctx.fillStyle = `rgba(255, 255, 255, ${this.opacity})`;
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
for (let i = 0; i < 70; i++) {
particles.push(new Particle());
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach((p) => {
p.update();
p.draw();
});
requestAnimationFrame(animate);
}
animate();
}
/* --------------------------------------------------------------------------
2. Floating Glass Bubbles Engine
-------------------------------------------------------------------------- */
function initGlassBubbles() {
const container = document.getElementById("bubbleContainer");
if (!container) return;
const totalBubbles = 22;
for (let i = 0; i < totalBubbles; i++) {
spawnBubble(container);
}
}
function spawnBubble(container) {
const bubble = document.createElement("div");
bubble.classList.add("bubble");
const size = Math.floor(Math.random() * 75) + 25;
bubble.style.width = `${size}px`;
bubble.style.height = `${size}px`;
const posX = Math.random() * 100;
bubble.style.left = `${posX}vw`;
const duration = Math.random() * 14 + 8;
const delay = Math.random() * 10;
bubble.style.animationDuration = `${duration}s`;
bubble.style.animationDelay = `${delay}s`;
container.appendChild(bubble);
}
/* --------------------------------------------------------------------------
3. Interactive 3D Perspective Tilt on Mouse Hover
-------------------------------------------------------------------------- */
function init3DTiltEffect() {
const tiltCards = document.querySelectorAll("[data-tilt]");
tiltCards.forEach((card) => {
card.addEventListener("mousemove", (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateX = ((y - centerY) / centerY) * -8;
const rotateY = ((x - centerX) / centerX) * 8;
card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) translateY(-4px)`;
});
card.addEventListener("mouseleave", () => {
card.style.transform = `perspective(1000px) rotateX(0deg) rotateY(0deg) translateY(0px)`;
});
});
}
/* --------------------------------------------------------------------------
4. Live Stat Counter Animation Engine
-------------------------------------------------------------------------- */
function initCounterAnimation() {
const statValues = document.querySelectorAll(".stat-value");
let animated = false;
const animateCounters = () => {
statValues.forEach((counter) => {
const target = +counter.getAttribute("data-target");
const speed = 45;
const updateCount = () => {
const count = +counter.innerText;
const inc = target / speed;
if (count < target) {
counter.innerText = Math.ceil(count + inc);
setTimeout(updateCount, 30);
} else {
counter.innerText = target;
}
};
updateCount();
});
};
window.addEventListener("scroll", () => {
const hero = document.getElementById("hero");
if (!hero) return;
const pos = hero.getBoundingClientRect().top;
if (pos < window.innerHeight && !animated) {
animateCounters();
animated = true;
}
});
animateCounters();
}
/* --------------------------------------------------------------------------
5. Dynamic Header Glass Blur on Scroll
-------------------------------------------------------------------------- */
function initHeaderScrollEffect() {
const header = document.getElementById("mainHeader");
if (!header) return;
window.addEventListener("scroll", () => {
if (window.scrollY > 40) {
header.classList.add("scrolled");
} else {
header.classList.remove("scrolled");
}
});
}
/* --------------------------------------------------------------------------
6. Mobile Navigation Menu Toggle
-------------------------------------------------------------------------- */
function initMobileNav() {
const toggleBtn = document.getElementById("mobileToggle");
const navLinks = document.getElementById("navLinks");
if (toggleBtn && navLinks) {
toggleBtn.addEventListener("click", () => {
navLinks.classList.toggle("active");
});
document.querySelectorAll(".nav-link").forEach((link) => {
link.addEventListener("click", () => {
navLinks.classList.remove("active");
});
});
}
}