Spaces:
Running
Running
Download script.js from QRS2026/quantumflow: direct link, hf CLI and curl.
- Browser
- Download file 6.08 kB
-
https://huggingface.co/spaces/QRS2026/quantumflow/resolve/main/script.js
- Command line
-
hf download hf://spaces/QRS2026/quantumflow/script.js
-
curl -L -o script.js https://huggingface.co/spaces/QRS2026/quantumflow/resolve/main/script.js
6.08 kB
| document.addEventListener('DOMContentLoaded', () => { | |
| /* -------------------------------------------------------- | |
| 1. Custom Cursor Logic | |
| -------------------------------------------------------- */ | |
| const cursorDot = document.getElementById('cursor-dot'); | |
| const cursorOutline = document.getElementById('cursor-outline'); | |
| // Mouse Movement | |
| window.addEventListener('mousemove', (e) => { | |
| const posX = e.clientX; | |
| const posY = e.clientY; | |
| // Dot follows instantly | |
| cursorDot.style.left = `${posX}px`; | |
| cursorDot.style.top = `${posY}px`; | |
| // Outline follows with slight delay (animation in CSS helps, but JS position is needed) | |
| cursorOutline.animate({ | |
| left: `${posX}px`, | |
| top: `${posY}px` | |
| }, { duration: 500, fill: "forwards" }); | |
| }); | |
| // Hover Effects | |
| const interactiveElements = document.querySelectorAll('a, button, .group, input, textarea, [role="button"]'); | |
| interactiveElements.forEach(el => { | |
| el.addEventListener('mouseenter', () => { | |
| document.body.classList.add('hovering'); | |
| }); | |
| el.addEventListener('mouseleave', () => { | |
| document.body.classList.remove('hovering'); | |
| }); | |
| }); | |
| /* -------------------------------------------------------- | |
| 2. Particle Network Background | |
| -------------------------------------------------------- */ | |
| const canvas = document.getElementById('particle-canvas'); | |
| const ctx = canvas.getContext('2d'); | |
| let particlesArray; | |
| // Resize Canvas | |
| canvas.width = window.innerWidth; | |
| canvas.height = window.innerHeight; | |
| class Particle { | |
| constructor(x, y, directionX, directionY, size, color) { | |
| this.x = x; | |
| this.y = y; | |
| this.directionX = directionX; | |
| this.directionY = directionY; | |
| this.size = size; | |
| this.color = color; | |
| } | |
| // Draw particle | |
| draw() { | |
| ctx.beginPath(); | |
| ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2, false); | |
| ctx.fillStyle = this.color; | |
| ctx.fill(); | |
| } | |
| // Update particle position | |
| update() { | |
| if (this.x > canvas.width || this.x < 0) { | |
| this.directionX = -this.directionX; | |
| } | |
| if (this.y > canvas.height || this.y < 0) { | |
| this.directionY = -this.directionY; | |
| } | |
| this.x += this.directionX; | |
| this.y += this.directionY; | |
| this.draw(); | |
| } | |
| } | |
| function initParticles() { | |
| particlesArray = []; | |
| let numberOfParticles = (canvas.height * canvas.width) / 15000; // Density | |
| for (let i = 0; i < numberOfParticles; i++) { | |
| let size = (Math.random() * 2) + 1; | |
| let x = (Math.random() * ((innerWidth - size * 2) - (size * 2)) + size * 2); | |
| let y = (Math.random() * ((innerHeight - size * 2) - (size * 2)) + size * 2); | |
| let directionX = (Math.random() * 0.4) - 0.2; | |
| let directionY = (Math.random() * 0.4) - 0.2; | |
| let color = '#06b6d4'; // Brand accent | |
| particlesArray.push(new Particle(x, y, directionX, directionY, size, color)); | |
| } | |
| } | |
| function connectParticles() { | |
| let opacityValue = 1; | |
| for (let a = 0; a < particlesArray.length; a++) { | |
| for (let b = a; b < particlesArray.length; b++) { | |
| let distance = ((particlesArray[a].x - particlesArray[b].x) * (particlesArray[a].x - particlesArray[b].x)) | |
| + ((particlesArray[a].y - particlesArray[b].y) * (particlesArray[a].y - particlesArray[b].y)); | |
| if (distance < (canvas.width/7) * (canvas.height/7)) { | |
| opacityValue = 1 - (distance / 20000); | |
| ctx.strokeStyle = 'rgba(6, 182, 212,' + opacityValue * 0.15 + ')'; // Very subtle lines | |
| ctx.lineWidth = 1; | |
| ctx.beginPath(); | |
| ctx.moveTo(particlesArray[a].x, particlesArray[a].y); | |
| ctx.lineTo(particlesArray[b].x, particlesArray[b].y); | |
| ctx.stroke(); | |
| } | |
| } | |
| } | |
| } | |
| function animateParticles() { | |
| requestAnimationFrame(animateParticles); | |
| ctx.clearRect(0, 0, innerWidth, innerHeight); | |
| for (let i = 0; i < particlesArray.length; i++) { | |
| particlesArray[i].update(); | |
| } | |
| connectParticles(); | |
| } | |
| window.addEventListener('resize', () => { | |
| canvas.width = innerWidth; | |
| canvas.height = innerHeight; | |
| initParticles(); | |
| }); | |
| initParticles(); | |
| animateParticles(); | |
| /* -------------------------------------------------------- | |
| 3. Intersection Observer for Scroll Animations | |
| -------------------------------------------------------- */ | |
| const revealElements = document.querySelectorAll('.reveal'); | |
| const revealCallback = (entries, observer) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| entry.target.classList.add('active'); | |
| observer.unobserve(entry.target); | |
| } | |
| }); | |
| }; | |
| const revealOptions = { | |
| threshold: 0.1, | |
| rootMargin: "0px 0px -50px 0px" | |
| }; | |
| const observer = new IntersectionObserver(revealCallback, revealOptions); | |
| revealElements.forEach(el => { | |
| observer.observe(el); | |
| }); | |
| // Smooth Scroll handling | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| e.preventDefault(); | |
| const targetId = this.getAttribute('href'); | |
| if (targetId === '#') return; | |
| const targetElement = document.querySelector(targetId); | |
| if (targetElement) { | |
| targetElement.scrollIntoView({ | |
| behavior: 'smooth' | |
| }); | |
| } | |
| }); | |
| }); | |
| }); | |