| |
| document.addEventListener('DOMContentLoaded', function() { |
| const mobileMenuBtn = document.querySelector('.mobile-menu-btn'); |
| const navLinks = document.querySelector('.nav-links'); |
| const navButtons = document.querySelector('.nav-buttons'); |
| |
| let menuOpen = false; |
| |
| mobileMenuBtn.addEventListener('click', function() { |
| if (!menuOpen) { |
| |
| const mobileMenu = document.createElement('div'); |
| mobileMenu.classList.add('mobile-menu'); |
| |
| |
| const navLinksClone = navLinks.cloneNode(true); |
| const navButtonsClone = navButtons.cloneNode(true); |
| |
| |
| mobileMenu.appendChild(navLinksClone); |
| mobileMenu.appendChild(navButtonsClone); |
| |
| |
| const header = document.querySelector('header'); |
| header.after(mobileMenu); |
| |
| |
| mobileMenuBtn.classList.add('open'); |
| |
| |
| const style = document.createElement('style'); |
| style.id = 'mobile-menu-styles'; |
| style.innerHTML = ` |
| .mobile-menu { |
| background-color: white; |
| padding: 20px; |
| box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1); |
| } |
| |
| .mobile-menu .nav-links { |
| display: flex; |
| flex-direction: column; |
| gap: 15px; |
| margin-bottom: 20px; |
| } |
| |
| .mobile-menu .nav-buttons { |
| display: flex; |
| flex-direction: column; |
| gap: 10px; |
| } |
| |
| .mobile-menu-btn.open span:nth-child(1) { |
| transform: rotate(45deg) translate(5px, 5px); |
| } |
| |
| .mobile-menu-btn.open span:nth-child(2) { |
| opacity: 0; |
| } |
| |
| .mobile-menu-btn.open span:nth-child(3) { |
| transform: rotate(-45deg) translate(7px, -6px); |
| } |
| `; |
| document.head.appendChild(style); |
| |
| menuOpen = true; |
| } else { |
| |
| const mobileMenu = document.querySelector('.mobile-menu'); |
| if (mobileMenu) { |
| mobileMenu.remove(); |
| } |
| |
| |
| const mobileMenuStyles = document.getElementById('mobile-menu-styles'); |
| if (mobileMenuStyles) { |
| mobileMenuStyles.remove(); |
| } |
| |
| |
| mobileMenuBtn.classList.remove('open'); |
| |
| menuOpen = false; |
| } |
| }); |
| |
| |
| window.addEventListener('resize', function() { |
| if (window.innerWidth > 768 && menuOpen) { |
| const mobileMenu = document.querySelector('.mobile-menu'); |
| if (mobileMenu) { |
| mobileMenu.remove(); |
| } |
| |
| const mobileMenuStyles = document.getElementById('mobile-menu-styles'); |
| if (mobileMenuStyles) { |
| mobileMenuStyles.remove(); |
| } |
| |
| mobileMenuBtn.classList.remove('open'); |
| |
| menuOpen = false; |
| } |
| }); |
| |
| |
| 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) { |
| targetElement.scrollIntoView({ |
| behavior: 'smooth' |
| }); |
| } |
| |
| |
| if (menuOpen) { |
| const mobileMenu = document.querySelector('.mobile-menu'); |
| if (mobileMenu) { |
| mobileMenu.remove(); |
| } |
| |
| const mobileMenuStyles = document.getElementById('mobile-menu-styles'); |
| if (mobileMenuStyles) { |
| mobileMenuStyles.remove(); |
| } |
| |
| mobileMenuBtn.classList.remove('open'); |
| |
| menuOpen = false; |
| } |
| }); |
| }); |
| |
| |
| const statsSection = document.querySelector('.stats'); |
| const statNumbers = document.querySelectorAll('.stat-item h3'); |
| |
| let animated = false; |
| |
| function animateStats() { |
| if (animated) return; |
| |
| const statsPosition = statsSection.getBoundingClientRect().top; |
| const screenPosition = window.innerHeight / 1.3; |
| |
| if (statsPosition < screenPosition) { |
| statNumbers.forEach(stat => { |
| const targetNumber = stat.textContent; |
| let currentNumber = 0; |
| const increment = Math.ceil(parseInt(targetNumber.replace(/[^0-9]/g, '')) / 50); |
| const duration = 1500; |
| const interval = duration / (parseInt(targetNumber.replace(/[^0-9]/g, '')) / increment); |
| |
| const counter = setInterval(() => { |
| currentNumber += increment; |
| |
| if (currentNumber >= parseInt(targetNumber.replace(/[^0-9]/g, ''))) { |
| stat.textContent = targetNumber; |
| clearInterval(counter); |
| } else { |
| if (targetNumber.includes('M')) { |
| stat.textContent = currentNumber + 'M+'; |
| } else if (targetNumber.includes('B')) { |
| stat.textContent = '$' + currentNumber + 'B+'; |
| } else { |
| stat.textContent = currentNumber + '+'; |
| } |
| } |
| }, interval); |
| }); |
| |
| animated = true; |
| } |
| } |
| |
| |
| window.addEventListener('scroll', animateStats); |
| |
| |
| animateStats(); |
| |
| |
| const hero = document.querySelector('.hero'); |
| |
| window.addEventListener('scroll', function() { |
| const scrollPosition = window.pageYOffset; |
| hero.style.backgroundPosition = `50% ${scrollPosition * 0.5}px`; |
| }); |
| |
| |
| const productCards = document.querySelectorAll('.product-card'); |
| |
| productCards.forEach(card => { |
| card.addEventListener('mouseenter', function() { |
| this.style.transform = 'translateY(-10px)'; |
| this.style.boxShadow = '0 10px 30px rgba(0, 0, 0, 0.1)'; |
| }); |
| |
| card.addEventListener('mouseleave', function() { |
| this.style.transform = 'translateY(0)'; |
| this.style.boxShadow = 'none'; |
| }); |
| }); |
| }); |