Spaces:
Running
Running
Download script.js from erfan14/creative-redesign: direct link, hf CLI and curl.
- Browser
- Download file 7.4 kB
-
https://huggingface.co/spaces/erfan14/creative-redesign/resolve/main/script.js
- Command line
-
hf download hf://spaces/erfan14/creative-redesign/script.js
-
curl -L -o script.js https://huggingface.co/spaces/erfan14/creative-redesign/resolve/main/script.js
7.4 kB
| // Mobile menu toggle | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const mobileMenuButton = document.getElementById('mobile-menu-button'); | |
| const mobileMenu = document.getElementById('mobile-menu'); | |
| // Initialize 3D AI Scene | |
| initAIScene(); | |
| // Scroll-based animation for 3D scene | |
| window.addEventListener('scroll', updateAIScene); | |
| if (mobileMenuButton && mobileMenu) { | |
| mobileMenuButton.addEventListener('click', function() { | |
| mobileMenu.classList.toggle('hidden'); | |
| // Change icon based on state | |
| const icon = mobileMenuButton.querySelector('i'); | |
| if (mobileMenu.classList.contains('hidden')) { | |
| icon.setAttribute('data-feather', 'menu'); | |
| } else { | |
| icon.setAttribute('data-feather', 'x'); | |
| } | |
| feather.replace(); | |
| }); | |
| } | |
| // Close mobile menu when clicking outside | |
| document.addEventListener('click', function(event) { | |
| const isClickInsideNav = mobileMenuButton.contains(event.target) || mobileMenu.contains(event.target); | |
| if (!isClickInsideNav && !mobileMenu.classList.contains('hidden')) { | |
| mobileMenu.classList.add('hidden'); | |
| const icon = mobileMenuButton.querySelector('i'); | |
| icon.setAttribute('data-feather', 'menu'); | |
| feather.replace(); | |
| } | |
| }); | |
| // Add fade-in animation to sections when they come into view | |
| const sections = document.querySelectorAll('section'); | |
| const observerOptions = { | |
| root: null, | |
| rootMargin: '0px', | |
| threshold: 0.1 | |
| }; | |
| const observer = new IntersectionObserver((entries, observer) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| entry.target.classList.add('fade-in'); | |
| observer.unobserve(entry.target); | |
| } | |
| }); | |
| }, observerOptions); | |
| sections.forEach(section => { | |
| observer.observe(section); | |
| }); | |
| }); | |
| // Technology-inspired 3D Scene Implementation | |
| let scene, camera, renderer; | |
| let particles = []; | |
| let connections = []; | |
| let scrollProgress = 0; | |
| function initAIScene() { | |
| // Create scene | |
| scene = new THREE.Scene(); | |
| scene.background = new THREE.Color(0x000000); | |
| // Create camera | |
| camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); | |
| camera.position.z = 15; | |
| // Create renderer | |
| renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true }); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| renderer.setPixelRatio(window.devicePixelRatio); | |
| document.getElementById('ai-3d-canvas').appendChild(renderer.domElement); | |
| // Create technology-inspired particle network | |
| createParticleNetwork(); | |
| // Add lighting | |
| const ambientLight = new THREE.AmbientLight(0x404040, 2); | |
| scene.add(ambientLight); | |
| const directionalLight = new THREE.DirectionalLight(0x00ffff, 1); | |
| directionalLight.position.set(5, 5, 5); | |
| scene.add(directionalLight); | |
| const pointLight1 = new THREE.PointLight(0x4dabf7, 1, 100); | |
| pointLight1.position.set(10, 10, 10); | |
| scene.add(pointLight1); | |
| const pointLight2 = new THREE.PointLight(0xe599f7, 1, 100); | |
| pointLight2.position.set(-10, -10, -10); | |
| scene.add(pointLight2); | |
| // Handle window resize | |
| window.addEventListener('resize', onWindowResize); | |
| // Initial render | |
| renderer.render(scene, camera); | |
| } | |
| function createParticleNetwork() { | |
| // Create particles in a grid formation | |
| const particleGeometry = new THREE.SphereGeometry(0.1, 16, 16); | |
| const particleMaterial = new THREE.MeshPhongMaterial({ | |
| color: 0x4dabf7, | |
| emissive: 0x4dabf7, | |
| emissiveIntensity: 0.3, | |
| shininess: 100 | |
| }); | |
| // Create particles in a structured grid | |
| for (let x = -8; x <= 8; x += 2) { | |
| for (let y = -5; y <= 5; y += 2) { | |
| for (let z = -3; z <= 3; z += 2) { | |
| // Skip some particles to create a more interesting pattern | |
| if (Math.random() > 0.3) { | |
| const particle = new THREE.Mesh(particleGeometry, particleMaterial.clone()); | |
| particle.position.set(x, y, z); | |
| particle.userData = { | |
| originalPosition: new THREE.Vector3(x, y, z), | |
| connected: false | |
| }; | |
| scene.add(particle); | |
| particles.push(particle); | |
| } | |
| } | |
| } | |
| } | |
| // Create connections between nearby particles | |
| const connectionMaterial = new THREE.LineBasicMaterial({ | |
| color: 0x4dabf7, | |
| transparent: true, | |
| opacity: 0.3 | |
| }); | |
| // Connect particles that are close to each other | |
| for (let i = 0; i < particles.length; i++) { | |
| for (let j = i + 1; j < particles.length; j++) { | |
| const particleA = particles[i]; | |
| const particleB = particles[j]; | |
| const distance = particleA.position.distanceTo(particleB.position); | |
| // Only connect particles that are relatively close | |
| if (distance < 4) { | |
| const points = [ | |
| particleA.position.clone(), | |
| particleB.position.clone() | |
| ]; | |
| const connectionGeometry = new THREE.BufferGeometry().setFromPoints(points); | |
| const connection = new THREE.Line(connectionGeometry, connectionMaterial.clone()); | |
| connection.userData = { | |
| source: particleA, | |
| target: particleB | |
| }; | |
| scene.add(connection); | |
| connections.push(connection); | |
| } | |
| } | |
| } | |
| } | |
| function onWindowResize() { | |
| camera.aspect = window.innerWidth / window.innerHeight; | |
| camera.updateProjectionMatrix(); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| } | |
| function updateAIScene() { | |
| // Calculate scroll progress (0 to 1) | |
| const scrollTop = window.pageYOffset; | |
| const docHeight = document.body.scrollHeight - window.innerHeight; | |
| scrollProgress = docHeight > 0 ? Math.min(1, scrollTop / docHeight) : 0; | |
| // Move particles based on scroll progress | |
| particles.forEach(particle => { | |
| const offset = scrollProgress * 5; | |
| particle.position.y = particle.userData.originalPosition.y + offset; | |
| particle.position.x = particle.userData.originalPosition.x + Math.sin(offset) * 0.5; | |
| particle.position.z = particle.userData.originalPosition.z + Math.cos(offset) * 0.5; | |
| // Change color based on position | |
| const hue = (offset * 0.1) % 1; | |
| particle.material.color.setHSL(hue, 1, 0.7); | |
| particle.material.emissive.setHSL(hue, 1, 0.3); | |
| }); | |
| // Update connections | |
| connections.forEach(connection => { | |
| const points = [ | |
| connection.userData.source.position.clone(), | |
| connection.userData.target.position.clone() | |
| ]; | |
| connection.geometry.setFromPoints(points); | |
| }); | |
| // Render the scene | |
| renderer.render(scene, camera); | |
| } | |
| // Remove the animate function since we're not doing automatic animations | |