// Modern JavaScript for Webrain IT Consulting LLC document.addEventListener('DOMContentLoaded', function() { console.log('Webrain IT Consulting - Modern Website Loaded'); // Initialize particles background initParticles(); // Enhanced smooth scrolling with offset document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { const offset = 100; const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - offset; window.scrollTo({ top: targetPosition, behavior: 'smooth' }); } }); }); // Advanced Intersection Observer with staggered animations const observerOptions = { threshold: 0.15, rootMargin: '0px 0px -100px 0px' }; const observer = new IntersectionObserver((entries) => { entries.forEach((entry, index) => { if (entry.isIntersecting) { // Stagger animation with delay based on index setTimeout(() => { entry.target.classList.add('animate-in'); }, index * 150); } }); }, observerOptions); // Observe all sections and cards for animation document.querySelectorAll('section, .modern-card, .gradient-border').forEach(element => { observer.observe(element); }); // Modern form handling with validation const contactForm = document.querySelector('#contact form'); if (contactForm) { contactForm.addEventListener('submit', function(e) { e.preventDefault(); // Add modern form submission with animation const submitBtn = contactForm.querySelector('button[type="submit"]'); const originalText = submitBtn.textContent; // Show loading state submitBtn.innerHTML = '
'; setTimeout(() => { // Success animation contactForm.classList.add('fade-in-scale'); alert('Thank you for your message! Our team will contact you within 24 hours.'); contactForm.reset(); submitBtn.textContent = originalText; }, 2000); }); } // Add custom cursor effect initCustomCursor(); // Add scroll progress indicator initScrollProgress(); // Add dynamic gradient background initDynamicBackground(); }); // Particle Background System function initParticles() { const container = document.getElementById('particles'); if (!container) return; for (let i = 0; i < 50; i++) { const particle = document.createElement('div'); particle.className = 'particle'; // Random position const left = Math.random() * 100; const top = Math.random() * 100; // Random size const size = Math.random() * 4 + 1; // Random animation delay const delay = Math.random() * 5; particle.style.cssText = ` left: ${left}%; top: ${top}%; width: ${size}px; height: ${size}px; animation-delay: ${delay}s; `; container.appendChild(particle); } } // Custom Cursor Effect function initCustomCursor() { const cursor = document.createElement('div'); cursor.className = 'custom-cursor'; document.body.appendChild(cursor); document.addEventListener('mousemove', (e) => { cursor.style.left = e.clientX + 'px'; cursor.style.top = e.clientY + 'px'; }); // Hide cursor on mouse out document.addEventListener('mouseout', () => { cursor.style.opacity = '0'; }); document.addEventListener('mouseover', () => { cursor.style.opacity = '1'; }); } // Scroll Progress Indicator function initScrollProgress() { const progressBar = document.createElement('div'); progressBar.style.cssText = ` position: fixed; top: 0; left: 0; width: 0%; height: 3px; background: linear-gradient(90deg, #3b82f6, #8b5cf6, #ec4899); z-index: 9998; transition: width 0.1s ease; `; document.body.appendChild(progressBar); window.addEventListener('scroll', () => { const windowHeight = document.documentElement.scrollHeight - window.innerHeight; const scrolled = (window.pageYOffset / windowHeight) * 100; progressBar.style.width = scrolled + '%'; }); } // Dynamic Background Gradient function initDynamicBackground() { const hero = document.getElementById('hero'); if (!hero) return; let mouseX = 0; let mouseY = 0; document.addEventListener('mousemove', (e) => { mouseX = e.clientX / window.innerWidth; mouseY = e.clientY / window.innerHeight; const gradient = ` radial-gradient( circle at ${mouseX * 100}% ${mouseY * 100}%, rgba(59, 130, 246, 0.3), rgba(139, 92, 246, 0.2), rgba(236, 72, 153, 0.1) ) `; hero.style.background = gradient + ', linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%)'; }); } // Enhanced Utility Functions function debounce(func, wait, immediate) { let timeout; return function executedFunction(...args) { const later = () => { timeout = null; if (!immediate) func(...args); }; const callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func(...args); }; } // Modern Typewriter Effect (if needed for future features) function typewriter(element, text, speed = 50) { let i = 0; element.innerHTML = ''; function type() { if (i < text.length) { element.innerHTML += text.charAt(i); i++; setTimeout(type, speed); } } type(); } // Dynamic Content Loading async function loadDynamicContent(url, containerId) { try { const response = await fetch(url); const data = await response.json(); const container = document.getElementById(containerId); if (container) { container.innerHTML = data.map(item => `

${item.title}

${item.description}

).join(''); } } catch (error) { console.error('Error loading dynamic content:', error); } }