Gomes20257/sparklesquad-pro
0
1 2document.addEventListener('DOMContentLoaded', function() {3 // Enhanced animation on scroll with IntersectionObserver4 const observerOptions = {5 threshold: 0.1,6 rootMargin: '0px 0px -50px 0px'7 };8 9 const observer = new IntersectionObserver((entries) => {10 entries.forEach(entry => {11 if (entry.isIntersecting) {12 entry.target.classList.add('animate');13 observer.unobserve(entry.target);14 }15 });16 }, observerOptions);17 18 document.querySelectorAll('.fade-in, .slide-up').forEach(el => {19 observer.observe(el);20 });21 22 // Crisper mobile menu toggle with animation23 window.toggleMobileMenu = function() {24 const menu = document.getElementById('mobile-menu');25 const icon = document.querySelector('[data-feather="menu"]');26 27 menu.classList.toggle('hidden');28 menu.classList.toggle('opacity-0');29 menu.classList.toggle('translate-y-2');30 31 if (menu.classList.contains('hidden')) {32 feather.replace();33 } else {34 // Replace menu icon with X when open35 icon.outerHTML = `<i data-feather="x" class="w-6 h-6"></i>`;36 feather.replace();37 }38 };39 40 // Enhanced form handling with validation41 const quoteForm = document.getElementById('quote-form');42 if (quoteForm) {43 quoteForm.addEventListener('submit', async function(e) {44 e.preventDefault();45 46 // Show loading state47 const submitBtn = this.querySelector('button[type="submit"]');48 const originalText = submitBtn.innerHTML;49 submitBtn.innerHTML = `<i data-feather="loader" class="animate-spin w-4 h-4 mr-2"></i>Processing...`;50 feather.replace();51 52 // Simulate API call53 await new Promise(resolve => setTimeout(resolve, 1500));54 55 // Show success feedback56 submitBtn.innerHTML = `<i data-feather="check-circle" class="w-4 h-4 mr-2"></i>Success!`;57 feather.replace();58 59 setTimeout(() => {60 submitBtn.innerHTML = originalText;61 feather.replace();62 this.reset();63 }, 2000);64 });65 }66 67 // Pixel-perfect smooth scrolling68 document.querySelectorAll('a[href^="#"]').forEach(anchor => {69 anchor.addEventListener('click', function(e) {70 e.preventDefault();71 const target = document.querySelector(this.getAttribute('href'));72 if (target) {73 window.scrollTo({74 top: target.offsetTop - 20,75 behavior: 'smooth'76 });77 }78 });79 });80 81 // Force hardware acceleration for animations82 document.querySelectorAll('.animate').forEach(el => {83 el.style.transform = 'translateZ(0)';84 });85});86 