-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
195 lines (158 loc) · 6.41 KB
/
Copy pathscript.js
File metadata and controls
195 lines (158 loc) · 6.41 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
document.addEventListener("DOMContentLoaded", () => {
// --- 1. LOADER LOGIC ---
const loader = document.getElementById("loader");
const loaderFill = document.getElementById("loader-fill");
const loaderPct = document.getElementById("loader-pct");
const loaderMsg = document.getElementById("loader-msg");
const messages = [
"INITIALIZING CORE MATRIX...",
"CONNECTING TO DIGITAL FRONTIER...",
"DECRYPTING NEURAL ASSETS...",
"COMPILING ARMILLARY ENGINE...",
"SYSTEMS ONLINE."
];
let progress = 0;
let msgIndex = 0;
const bootInterval = setInterval(() => {
progress += Math.floor(Math.random() * 10) + 1;
if (progress > 100) progress = 100;
loaderFill.style.width = `${progress}%`;
loaderPct.textContent = `${progress}%`;
if (progress > (msgIndex + 1) * 20 && msgIndex < messages.length - 1) {
msgIndex++;
loaderMsg.textContent = messages[msgIndex];
}
if (progress === 100) {
clearInterval(bootInterval);
setTimeout(() => {
loader.style.opacity = '0';
loader.style.visibility = 'hidden';
initMetrics();
}, 600);
}
}, 70);
// --- 2. CANVAS BACKGROUND ANIMATION ---
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
let width, height, particles;
function initCanvas() {
width = canvas.width = window.innerWidth;
height = canvas.height = window.innerHeight;
particles = [];
const particleCount = window.innerWidth < 768 ? 40 : 80;
for (let i = 0; i < particleCount; i++) {
particles.push({
x: Math.random() * width,
y: Math.random() * height,
vx: (Math.random() - 0.5) * 0.5,
vy: (Math.random() - 0.5) * 0.5,
size: Math.random() * 2 + 0.5
});
}
}
function animateCanvas() {
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = "rgba(148, 163, 184, 0.5)";
ctx.strokeStyle = "rgba(0, 245, 255, 0.05)";
particles.forEach(p => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0 || p.x > width) p.vx *= -1;
if (p.y < 0 || p.y > height) p.vy *= -1;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
ctx.fill();
});
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 120) {
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.stroke();
}
}
}
requestAnimationFrame(animateCanvas);
}
initCanvas();
animateCanvas();
window.addEventListener("resize", initCanvas);
// --- 3. CUSTOM CURSOR LOGIC ---
const cursorDot = document.getElementById("cur-dot");
const cursorRing = document.getElementById("cur-ring");
if (window.matchMedia("(pointer: fine)").matches) {
window.addEventListener("mousemove", (e) => {
const posX = e.clientX;
const posY = e.clientY;
cursorDot.style.left = `${posX}px`;
cursorDot.style.top = `${posY}px`;
cursorRing.animate({
left: `${posX}px`,
top: `${posY}px`
}, { duration: 150, fill: "forwards" });
});
}
// --- 4. 3D CARD TILT EFFECT (UPDATED FOR MULTIPLE CARDS) ---
const dlWraps = document.querySelectorAll(".dl-wrap");
if (window.matchMedia("(pointer: fine)").matches) {
dlWraps.forEach(dlWrap => {
const dlCard = dlWrap.querySelector(".dl-card");
if (dlCard) {
dlWrap.addEventListener("mousemove", (e) => {
const rect = dlWrap.getBoundingClientRect();
const x = e.clientX - rect.left - rect.width / 2;
const y = e.clientY - rect.top - rect.height / 2;
const multiplier = 15;
const xRotate = -(y / (rect.height / 2)) * multiplier;
const yRotate = (x / (rect.width / 2)) * multiplier;
dlCard.style.transform = `rotateX(${xRotate}deg) rotateY(${yRotate}deg)`;
});
dlWrap.addEventListener("mouseleave", () => {
dlCard.style.transform = `rotateX(0) rotateY(0)`;
});
}
});
}
// --- 5. NUMBER COUNTER METRICS ---
function initMetrics() {
const counters = document.querySelectorAll(".m-val");
const speed = 200;
counters.forEach(counter => {
const updateCount = () => {
const target = +counter.getAttribute("data-count");
const count = +counter.innerText;
const inc = target / speed;
if (count < target) {
counter.innerText = Math.ceil(count + inc);
setTimeout(updateCount, 15);
} else {
counter.innerText = target;
}
};
// Only animate if the target is greater than 0
if (+counter.getAttribute("data-count") !== 0) {
updateCount();
}
});
}
// --- 6. SCROLL ANIMATION OBSERVER ---
const observerOptions = {
threshold: 0.1,
rootMargin: "0px 0px -50px 0px"
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add("active");
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('.sc-rev').forEach((el) => {
observer.observe(el);
});
});