Spaces:
Running
Running
File size: 11,481 Bytes
af9f1ed | 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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | // Wait for DOM to be ready
document.addEventListener('DOMContentLoaded', () => {
initCustomCursor();
initParticles();
initScrollReveal();
initCounterAnimation();
initMagneticButtons();
initTiltEffect();
initSmoothScroll();
initPageTransitions();
initMarqueeSpeed();
});
// Custom Cursor
function initCustomCursor() {
if (window.matchMedia("(max-width: 768px)").matches) return;
const cursorDot = document.getElementById('cursor-dot');
const cursorOutline = document.getElementById('cursor-outline');
let mouseX = 0, mouseY = 0;
let outlineX = 0, outlineY = 0;
document.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
cursorDot.style.left = `${mouseX}px`;
cursorDot.style.top = `${mouseY}px`;
});
// Smooth follow for outline
function animate() {
outlineX += (mouseX - outlineX) * 0.15;
outlineY += (mouseY - outlineY) * 0.15;
cursorOutline.style.left = `${outlineX}px`;
cursorOutline.style.top = `${outlineY}px`;
requestAnimationFrame(animate);
}
animate();
// Hover effects
const interactiveElements = document.querySelectorAll('a, button, [data-tilt], input, textarea');
interactiveElements.forEach(el => {
el.addEventListener('mouseenter', () => {
cursorDot.classList.add('hovering');
cursorOutline.classList.add('hovering');
});
el.addEventListener('mouseleave', () => {
cursorDot.classList.remove('hovering');
cursorOutline.classList.remove('hovering');
});
});
}
// Particle System
function initParticles() {
const canvas = document.getElementById('particleCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let particles = [];
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resize();
window.addEventListener('resize', resize);
class Particle {
constructor() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.size = Math.random() * 2 + 0.5;
this.speedX = Math.random() * 1 - 0.5;
this.speedY = Math.random() * 1 - 0.5;
this.opacity = Math.random() * 0.5 + 0.1;
}
update() {
this.x += this.speedX;
this.y += this.speedY;
if (this.x > canvas.width) this.x = 0;
if (this.x < 0) this.x = canvas.width;
if (this.y > canvas.height) this.y = 0;
if (this.y < 0) this.y = canvas.height;
}
draw() {
ctx.fillStyle = `rgba(139, 92, 246, ${this.opacity})`;
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
// Create particles
for (let i = 0; i < 50; i++) {
particles.push(new Particle());
}
// Animation loop
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(particle => {
particle.update();
particle.draw();
});
// Connect particles
particles.forEach((a, index) => {
particles.slice(index + 1).forEach(b => {
const dx = a.x - b.x;
const dy = a.y - b.y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 100) {
ctx.strokeStyle = `rgba(139, 92, 246, ${0.1 * (1 - distance / 100)})`;
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(a.x, a.y);
ctx.lineTo(b.x, b.y);
ctx.stroke();
}
});
});
requestAnimationFrame(animate);
}
animate();
}
// Scroll Reveal
function initScrollReveal() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// Add delay if specified
const delay = entry.target.dataset.delay || 0;
setTimeout(() => {
entry.target.classList.add('revealed');
}, delay);
}
});
}, observerOptions);
document.querySelectorAll('.reveal-on-scroll').forEach(el => {
observer.observe(el);
});
}
// Counter Animation
function initCounterAnimation() {
const counters = document.querySelectorAll('.counter');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const counter = entry.target;
const target = parseInt(counter.getAttribute('data-target'));
const duration = 2000;
const step = target / (duration / 16);
let current = 0;
const updateCounter = () => {
current += step;
if (current < target) {
counter.textContent = Math.floor(current);
requestAnimationFrame(updateCounter);
} else {
counter.textContent = target;
}
};
updateCounter();
observer.unobserve(counter);
}
});
}, { threshold: 0.5 });
counters.forEach(counter => observer.observe(counter));
}
// Magnetic Buttons
function initMagneticButtons() {
if (window.matchMedia("(max-width: 768px)").matches) return;
const buttons = document.querySelectorAll('.magnetic-btn');
buttons.forEach(btn => {
btn.addEventListener('mousemove', (e) => {
const rect = btn.getBoundingClientRect();
const x = e.clientX - rect.left - rect.width / 2;
const y = e.clientY - rect.top - rect.height / 2;
btn.style.transform = `translate(${x * 0.3}px, ${y * 0.3}px)`;
});
btn.addEventListener('mouseleave', () => {
btn.style.transform = 'translate(0, 0)';
});
});
}
// 3D Tilt Effect
function initTiltEffect() {
if (window.matchMedia("(max-width: 768px)").matches) return;
const cards = document.querySelectorAll('[data-tilt]');
cards.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) / 10;
const rotateY = (centerX - x) / 10;
card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale3d(1.05, 1.05, 1.05)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'perspective(1000px) rotateX(0) rotateY(0) scale3d(1, 1, 1)';
});
});
}
// Smooth Scroll
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
// Page Transitions
function initPageTransitions() {
const transition = document.getElementById('pageTransition');
const links = document.querySelectorAll('a[href^="/"], a[href^="."]');
links.forEach(link => {
link.addEventListener('click', (e) => {
const href = link.getAttribute('href');
if (href && !href.startsWith('#')) {
e.preventDefault();
transition.classList.add('active');
setTimeout(() => {
window.location.href = href;
}, 500);
}
});
});
}
// Marquee Speed based on scroll
function initMarqueeSpeed() {
const marquee = document.querySelector('.marquee-content');
if (!marquee) return;
let scrollSpeed = 0;
let lastScrollY = window.scrollY;
window.addEventListener('scroll', () => {
const currentScrollY = window.scrollY;
scrollSpeed = Math.abs(currentScrollY - lastScrollY);
lastScrollY = currentScrollY;
const speed = Math.max(20 - scrollSpeed, 5);
marquee.style.animationDuration = `${speed}s`;
});
}
// Text Scramble Effect for Hero
class TextScramble {
constructor(el) {
this.el = el;
this.chars = '!<>-_\\/[]{}—=+*^?#________';
this.update = this.update.bind(this);
}
setText(newText) {
const oldText = this.el.innerText;
const length = Math.max(oldText.length, newText.length);
const promise = new Promise((resolve) => this.resolve = resolve);
this.queue = [];
for (let i = 0; i < length; i++) {
const from = oldText[i] || '';
const to = newText[i] || '';
const start = Math.floor(Math.random() * 40);
const end = start + Math.floor(Math.random() * 40);
this.queue.push({ from, to, start, end });
}
cancelAnimationFrame(this.frameRequest);
this.frame = 0;
this.update();
return promise;
}
update() {
let output = '';
let complete = 0;
for (let i = 0, n = this.queue.length; i < n; i++) {
let { from, to, start, end, char } = this.queue[i];
if (this.frame >= end) {
complete++;
output += to;
} else if (this.frame >= start) {
if (!char || Math.random() < 0.28) {
char = this.randomChar();
this.queue[i].char = char;
}
output += `<span class="dud">${char}</span>`;
} else {
output += from;
}
}
this.el.innerHTML = output;
if (complete === this.queue.length) {
this.resolve();
} else {
this.frameRequest = requestAnimationFrame(this.update);
this.frame++;
}
}
randomChar() {
return this.chars[Math.floor(Math.random() * this.chars.length)];
}
}
// Parallax Effect
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const parallaxElements = document.querySelectorAll('.parallax');
parallaxElements.forEach(el => {
const speed = el.dataset.speed || 0.5;
el.style.transform = `translateY(${scrolled * speed}px)`;
});
});
// Form Interaction
document.querySelectorAll('input, textarea').forEach(input => {
input.addEventListener('focus', () => {
document.body.style.cursor = 'text';
});
input.addEventListener('blur', () => {
document.body.style.cursor = 'none';
});
}); |