File size: 7,525 Bytes
e12f096 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | // Mobile menu toggle
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) {
// Create mobile menu
const mobileMenu = document.createElement('div');
mobileMenu.classList.add('mobile-menu');
// Clone nav links and buttons
const navLinksClone = navLinks.cloneNode(true);
const navButtonsClone = navButtons.cloneNode(true);
// Append to mobile menu
mobileMenu.appendChild(navLinksClone);
mobileMenu.appendChild(navButtonsClone);
// Add mobile menu after header
const header = document.querySelector('header');
header.after(mobileMenu);
// Animate menu button
mobileMenuBtn.classList.add('open');
// Add styles for mobile menu
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 {
// Remove mobile menu
const mobileMenu = document.querySelector('.mobile-menu');
if (mobileMenu) {
mobileMenu.remove();
}
// Remove mobile menu styles
const mobileMenuStyles = document.getElementById('mobile-menu-styles');
if (mobileMenuStyles) {
mobileMenuStyles.remove();
}
// Reset menu button
mobileMenuBtn.classList.remove('open');
menuOpen = false;
}
});
// Close mobile menu on window resize
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;
}
});
// 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) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
// Close mobile menu if open
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;
}
});
});
// Animate stats on scroll
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; // ms
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;
}
}
// Check if stats are in view on scroll
window.addEventListener('scroll', animateStats);
// Check on page load
animateStats();
// Parallax effect for hero section
const hero = document.querySelector('.hero');
window.addEventListener('scroll', function() {
const scrollPosition = window.pageYOffset;
hero.style.backgroundPosition = `50% ${scrollPosition * 0.5}px`;
});
// Product card hover effect
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';
});
});
}); |