// Main JavaScript for Didgit.co.uk document.addEventListener('DOMContentLoaded', function() { // Hero Slider const slides = document.querySelectorAll('.slide'); const dots = document.querySelectorAll('.dot'); let currentSlide = 0; function showSlide(n) { slides.forEach(slide => slide.classList.remove('active')); dots.forEach(dot => dot.classList.remove('active')); currentSlide = (n + slides.length) % slides.length; slides[currentSlide].classList.add('active'); dots[currentSlide].classList.add('active'); } function nextSlide() { showSlide(currentSlide + 1); } // Auto slide every 5 seconds setInterval(nextSlide, 5000); // Dot navigation dots.forEach((dot, index) => { dot.addEventListener('click', () => { showSlide(index); }); }); // Smooth scrolling for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const targetId = this.getAttribute('href'); if (targetId === '#') return; const targetElement = document.querySelector(targetId); if (targetElement) { window.scrollTo({ top: targetElement.offsetTop - 80, behavior: 'smooth' }); } }); }); // Animation on scroll const animateOnScroll = function() { const elements = document.querySelectorAll('.animate-on-scroll'); elements.forEach(element => { const elementPosition = element.getBoundingClientRect().top; const windowHeight = window.innerHeight; if (elementPosition < windowHeight - 100) { element.classList.add('animate-fadeInUp'); } }); }; // Initialize animations window.addEventListener('scroll', animateOnScroll); animateOnScroll(); // Form submission handling const contactForm = document.querySelector('#contact form'); if (contactForm) { contactForm.addEventListener('submit', function(e) { e.preventDefault(); // Get form values const name = this.querySelector('#name').value; const email = this.querySelector('#email').value; const message = this.querySelector('#message').value; // Simple validation if (!name || !email || !message) { alert('Please fill in all fields'); return; } // Here you would typically send the form data to a server console.log('Form submitted:', { name, email, message }); alert('Thank you for your message! We will get back to you soon.'); // Reset form this.reset(); }); } }); // Intersection Observer for animations const observerOptions = { threshold: 0.1 }; const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate-fadeInUp'); observer.unobserve(entry.target); } }); }, observerOptions); document.querySelectorAll('.animate-on-scroll').forEach(element => { observer.observe(element); });