// Wait for the DOM to be fully loaded document.addEventListener('DOMContentLoaded', function() { // Smooth scrolling for navigation links document.querySelectorAll('nav a').forEach(anchor => { anchor.addEventListener('click', function(e) { e.preventDefault(); const targetId = this.getAttribute('href'); const targetElement = document.querySelector(targetId); window.scrollTo({ top: targetElement.offsetTop - 70, behavior: 'smooth' }); }); }); // Add animation to car items when they come into view const carItems = document.querySelectorAll('.car-item'); // Simple function to check if an element is in viewport function isInViewport(element) { const rect = element.getBoundingClientRect(); return ( rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth) ); } // Function to add animation class when elements are in viewport function checkVisibility() { carItems.forEach(item => { if (isInViewport(item)) { item.classList.add('visible'); } }); } // Check visibility on scroll window.addEventListener('scroll', checkVisibility); // Check visibility on initial load checkVisibility(); });