Spaces:
Running
Running
Download script.js from Iboytech/data-alchemy-nexus: direct link, hf CLI and curl.
- Browser
- Download file 6.43 kB
-
https://huggingface.co/spaces/Iboytech/data-alchemy-nexus/resolve/main/script.js
- Command line
-
hf download hf://spaces/Iboytech/data-alchemy-nexus/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Iboytech/data-alchemy-nexus/resolve/main/script.js
6.43 kB
| // Enhanced smooth scrolling for anchor links | |
| document.addEventListener('DOMContentLoaded', () => { | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| e.preventDefault(); | |
| const target = document.querySelector(this.getAttribute('href')); | |
| if (target) { | |
| const headerHeight = 80; // Adjust based on your navbar height | |
| const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - headerHeight; | |
| window.scrollTo({ | |
| top: targetPosition, | |
| behavior: 'smooth' | |
| }); | |
| } | |
| }); | |
| }); | |
| // Enhanced Intersection Observer for animations | |
| const observerOptions = { | |
| threshold: 0.05, | |
| rootMargin: '0px 0px -100px 0px' | |
| }; | |
| const observer = new IntersectionObserver((entries) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| entry.target.classList.add('animate-fade-in'); | |
| // Add stagger animation for child elements | |
| if (entry.target.classList.contains('stagger-animation')) { | |
| const children = entry.target.children; | |
| Array.from(children).forEach((child, index) => { | |
| child.style.animationDelay = `${index * 0.1}s`; | |
| }); | |
| } | |
| } | |
| }); | |
| }, observerOptions); | |
| // Observe elements for animation | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const animatedElements = document.querySelectorAll('.service-card, .portfolio-item, .contact-form'); | |
| animatedElements.forEach(el => { | |
| observer.observe(el); | |
| }); | |
| }); | |
| // Form handling | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const contactForm = document.querySelector('form'); | |
| if (contactForm) { | |
| contactForm.addEventListener('submit', (e) => { | |
| e.preventDefault(); | |
| // Get form data | |
| const formData = new FormData(contactForm); | |
| const data = Object.fromEntries(formData); | |
| // Simulate form submission | |
| const submitBtn = contactForm.querySelector('button[type="submit"]'); | |
| const originalText = submitBtn.innerHTML; | |
| submitBtn.innerHTML = 'Sending...'; | |
| submitBtn.disabled = true; | |
| // Simulate API call | |
| setTimeout(() => { | |
| submitBtn.innerHTML = 'Message Sent!'; | |
| submitBtn.classList.remove('bg-gradient-to-r', 'from-primary-500', 'to-secondary-500'); | |
| submitBtn.classList.add('bg-green-500'); | |
| // Reset form | |
| contactForm.reset(); | |
| // Reset button after 3 seconds | |
| setTimeout(() => { | |
| submitBtn.innerHTML = originalText; | |
| submitBtn.disabled = false; | |
| submitBtn.classList.remove('bg-green-500'); | |
| submitBtn.classList.add('bg-gradient-to-r', 'from-primary-500', 'to-secondary-500'); | |
| }, 3000); | |
| }, 1500); | |
| }); | |
| } | |
| }); | |
| // Theme toggle functionality (if needed for future light mode) | |
| const themeToggle = { | |
| init() { | |
| this.toggleBtn = document.getElementById('theme-toggle'); | |
| if (this.toggleBtn) { | |
| this.toggleBtn.addEventListener('click', () => { | |
| document.documentElement.classList.toggle('dark'); | |
| localStorage.setItem('theme', document.documentElement.classList.contains('dark') ? 'dark' : 'light'); | |
| }); | |
| } | |
| } | |
| }; | |
| // Initialize theme toggle | |
| themeToggle.init(); | |
| // Enhanced fade-in animation class | |
| const style = document.createElement('style'); | |
| style.textContent = ` | |
| @keyframes fadeIn { | |
| from { | |
| opacity: 0; | |
| transform: translateY(40px) scale(0.95); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateY(0) scale(1); | |
| } | |
| } | |
| .animate-fade-in { | |
| animation: fadeIn 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards; | |
| } | |
| .service-card, .portfolio-item, .contact-form { | |
| opacity: 0; | |
| } | |
| /* Magnetic button effect implementation */ | |
| .magnetic-area { | |
| position: relative; | |
| display: inline-block; | |
| } | |
| .magnetic-btn { | |
| transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| // Magnetic button effect | |
| class MagneticButton { | |
| constructor(element) { | |
| this.element = element; | |
| this.area = element.parentElement; | |
| this.bounding = this.area.getBoundingClientRect(); | |
| this.area.addEventListener('mousemove', this.handleMouseMove.bind(this)); | |
| this.area.addEventListener('mouseleave', this.handleMouseLeave.bind(this)); | |
| } | |
| handleMouseMove(e) { | |
| const x = e.clientX - this.bounding.left - this.bounding.width / 2; | |
| const y = e.clientY - this.bounding.top - this.bounding.height / 2; | |
| const strength = 20; | |
| const newX = (x / this.bounding.width) * strength; | |
| const newY = (y / this.bounding.height) * strength; | |
| this.element.style.transform = `translate(${newX}px, ${newY}px) scale(1.05)`; | |
| } | |
| handleMouseLeave() { | |
| this.element.style.transform = 'translate(0px, 0px) scale(1)`; | |
| } | |
| } | |
| // Initialize magnetic buttons | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const magneticButtons = document.querySelectorAll('.magnetic-btn'); | |
| magneticButtons.forEach(btn => { | |
| new MagneticButton(btn); | |
| }); | |
| }); | |
| // Enhanced parallax effect | |
| window.addEventListener('scroll', () => { | |
| const scrolled = window.pageYOffset; | |
| const parallaxElements = document.querySelectorAll('.parallax'); | |
| parallaxElements.forEach(element => { | |
| const speed = element.dataset.speed || 0.3; | |
| element.style.transform = `translateY(${scrolled * speed}px)`; | |
| }); | |
| }); | |
| // Parallax effect for hero section | |
| window.addEventListener('scroll', () => { | |
| const scrolled = window.pageYOffset; | |
| const parallaxElements = document.querySelectorAll('.parallax'); | |
| parallaxElements.forEach(element => { | |
| const speed = element.dataset.speed || 0.5; | |
| element.style.transform = `translateY(${scrolled * speed}px)`; | |
| }); | |
| }); | |