// Mobile Menu Toggle document.addEventListener('DOMContentLoaded', function() { const mobileToggle = document.querySelector('.mobile-toggle'); const navLinks = document.querySelector('.nav-links'); if (mobileToggle) { mobileToggle.addEventListener('click', function() { navLinks.classList.toggle('active'); this.classList.toggle('active'); }); // Close menu when clicking on a link document.querySelectorAll('.nav-links a').forEach(link => { link.addEventListener('click', () => { navLinks.classList.remove('active'); mobileToggle.classList.remove('active'); }); }); // Close menu when clicking outside document.addEventListener('click', function(e) { if (!mobileToggle.contains(e.target) && !navLinks.contains(e.target)) { navLinks.classList.remove('active'); mobileToggle.classList.remove('active'); } }); } // Smooth scroll for anchor links 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' }); } }); }); // Navbar scroll effect let lastScroll = 0; const navbar = document.querySelector('.navbar'); window.addEventListener('scroll', () => { const currentScroll = window.pageYOffset; if (currentScroll > 100) { navbar.style.boxShadow = '0 5px 30px rgba(0, 217, 255, 0.1)'; } else { navbar.style.boxShadow = 'none'; } lastScroll = currentScroll; }); // Intersection Observer for fade-in animations const observerOptions = { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }; const observer = new IntersectionObserver(function(entries) { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.style.opacity = '1'; entry.target.style.transform = 'translateY(0)'; } }); }, observerOptions); // Observe elements for animation const animateElements = document.querySelectorAll('.gen-ai-card, .service-card, .timeline-item'); animateElements.forEach(el => { el.style.opacity = '0'; el.style.transform = 'translateY(30px)'; el.style.transition = 'opacity 0.6s ease, transform 0.6s ease'; observer.observe(el); }); // Counter animation for stats const animateCounter = (element, target, duration = 2000) => { let start = 0; const increment = target / (duration / 16); const isPercentage = element.textContent.includes('%'); const suffix = isPercentage ? '%' : '+'; const timer = setInterval(() => { start += increment; if (start >= target) { element.textContent = target + suffix; clearInterval(timer); } else { element.textContent = Math.floor(start) + suffix; } }, 16); }; // Trigger counter animation when stats are visible const statsObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting && !entry.target.classList.contains('counted')) { entry.target.classList.add('counted'); const numbers = entry.target.querySelectorAll('.stat-number'); numbers.forEach(num => { const text = num.textContent; const value = parseInt(text.replace(/\D/g, '')); animateCounter(num, value); }); } }); }); const statsSection = document.querySelector('.hero-stats'); if (statsSection) { statsObserver.observe(statsSection); } // Parallax effect for hero background window.addEventListener('scroll', () => { const scrolled = window.pageYOffset; const heroBg = document.querySelector('.hero-bg'); if (heroBg) { heroBg.style.transform = `translateY(${scrolled * 0.5}px)`; } }); // Form validation for contact page const contactForm = document.querySelector('.contact-form'); if (contactForm) { contactForm.addEventListener('submit', function(e) { e.preventDefault(); const name = this.querySelector('input[name="name"]'); const email = this.querySelector('input[name="email"]'); const message = this.querySelector('textarea[name="message"]'); let isValid = true; // Clear previous errors document.querySelectorAll('.error-message').forEach(el => el.remove()); // Validate name if (name.value.trim().length < 2) { showError(name, 'Please enter your full name'); isValid = false; } // Validate email const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(email.value)) { showError(email, 'Please enter a valid email address'); isValid = false; } // Validate message if (message.value.trim().length < 10) { showError(message, 'Message must be at least 10 characters'); isValid = false; } if (isValid) { // Show success message const successDiv = document.createElement('div'); successDiv.className = 'success-message'; successDiv.textContent = 'Thank you! Your message has been sent successfully.'; successDiv.style.cssText = ` background: linear-gradient(135deg, #00d9ff 0%, #8b5cf6 100%); color: white; padding: 1rem; border-radius: 10px; margin-bottom: 1rem; text-align: center; `; contactForm.insertBefore(successDiv, contactForm.firstChild); // Reset form this.reset(); // Remove success message after 5 seconds setTimeout(() => successDiv.remove(), 5000); } }); } function showError(input, message) { const errorDiv = document.createElement('div'); errorDiv.className = 'error-message'; errorDiv.textContent = message; errorDiv.style.cssText = ` color: #ec4899; font-size: 0.9rem; margin-top: 0.5rem; `; input.parentElement.appendChild(errorDiv); input.style.borderColor = '#ec4899'; // Remove error on input input.addEventListener('input', function() { const error = this.parentElement.querySelector('.error-message'); if (error) error.remove(); this.style.borderColor = ''; }); } // Pricing toggle for annual/monthly const pricingToggle = document.querySelector('.pricing-toggle'); if (pricingToggle) { const buttons = pricingToggle.querySelectorAll('button'); const prices = document.querySelectorAll('.price-amount'); buttons.forEach(button => { button.addEventListener('click', function() { buttons.forEach(btn => btn.classList.remove('active')); this.classList.add('active'); const isAnnual = this.dataset.period === 'annual'; prices.forEach(price => { const monthly = price.dataset.monthly; const annual = price.dataset.annual; price.textContent = isAnnual ? annual : monthly; }); }); }); } // Tool demo interaction const toolDemos = document.querySelectorAll('.tool-demo'); toolDemos.forEach(demo => { const button = demo.querySelector('.demo-button'); if (button) { button.addEventListener('click', function() { const result = demo.querySelector('.demo-result'); if (result) { result.style.display = 'block'; result.style.animation = 'fadeInUp 0.5s ease'; this.textContent = 'Analyzing...'; this.disabled = true; setTimeout(() => { this.textContent = 'Run Analysis'; this.disabled = false; }, 2000); } }); } }); // Add loading state to external links document.querySelectorAll('a[target="_blank"]').forEach(link => { link.addEventListener('click', function(e) { const originalText = this.textContent; this.style.opacity = '0.7'; setTimeout(() => { this.style.opacity = '1'; }, 300); }); }); // Keyboard navigation document.addEventListener('keydown', function(e) { // ESC to close mobile menu if (e.key === 'Escape') { navLinks.classList.remove('active'); if (mobileToggle) { mobileToggle.classList.remove('active'); } } }); // Add hover effect to cards const cards = document.querySelectorAll('.gen-ai-card, .service-card, .pricing-card'); cards.forEach(card => { card.addEventListener('mouseenter', function() { this.style.transition = 'all 0.3s ease'; }); }); // Lazy load images if any const images = document.querySelectorAll('img[data-src]'); const imageObserver = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { const img = entry.target; img.src = img.dataset.src; img.removeAttribute('data-src'); imageObserver.unobserve(img); } }); }); images.forEach(img => imageObserver.observe(img)); // Performance optimization: Debounce scroll events function debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; } // Add active state to current page in navigation const currentPage = window.location.pathname.split('/').pop() || 'index.html'; document.querySelectorAll('.nav-links a').forEach(link => { if (link.getAttribute('href') === currentPage) { link.classList.add('active'); } }); console.log('🚀 HackKnow - Gen AI SEO Platform Loaded Successfully'); });