File size: 5,988 Bytes
df417f0 |
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 |
// Debounce utility
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Active navigation highlighting
function initNavigation() {
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link');
if (!sections.length || !navLinks.length) return;
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const id = entry.target.id;
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${id}`) {
link.classList.add('active');
}
});
}
});
}, {
rootMargin: '-30% 0px -70% 0px',
threshold: 0
});
sections.forEach(section => observer.observe(section));
}
// Mobile menu toggle
function initMobileMenu() {
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
const mobileMenuLinks = mobileMenu?.querySelectorAll('a');
if (!mobileMenuBtn || !mobileMenu) return;
mobileMenuBtn.addEventListener('click', () => {
mobileMenu.classList.toggle('open');
});
// Close menu when link is clicked
mobileMenuLinks?.forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.remove('open');
});
});
// Close menu on escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
mobileMenu.classList.remove('open');
}
});
}
// Animate stats counters
function animateStats() {
const stats = document.querySelectorAll('[data-stat]');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = entry.target;
const finalValue = parseInt(target.getAttribute('data-stat'));
const duration = 1500;
const startTime = performance.now();
function updateCounter(currentTime) {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
const currentValue = Math.floor(progress * finalValue);
target.textContent = currentValue.toLocaleString();
if (progress < 1) {
requestAnimationFrame(updateCounter);
} else {
target.textContent = finalValue.toLocaleString();
}
}
requestAnimationFrame(updateCounter);
observer.unobserve(target);
}
});
}, { threshold: 0.5 });
stats.forEach(stat => observer.observe(stat));
}
// Add fade-in animation to cards on scroll
function initScrollAnimations() {
const cards = document.querySelectorAll('.glass-card, .spec-block, .node-card, .benefit-card, .use-case-card, .component-card, .network-card, .learning-card, .path-card, .final-card');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in-up');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
cards.forEach(card => observer.observe(card));
}
// Smooth scroll for navigation links
function initSmoothScroll() {
const links = document.querySelectorAll('a[href^="#"]');
links.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetId = link.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
const headerOffset = 80;
const elementPosition = targetElement.offsetTop;
const offsetPosition = elementPosition - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
// Update URL without jumping
history.pushState(null, null, targetId);
}
});
});
}
// Parallax effect for hero background
function initParallax() {
const hero = document.getElementById('hero');
if (!hero) return;
window.addEventListener('scroll', debounce(() => {
const scrolled = window.pageYOffset;
const rate = scrolled * -0.5;
hero.style.transform = `translateY(${rate}px)`;
}, 10));
}
// Handle anchor links on page load
function handleAnchorLinks() {
if (window.location.hash) {
const element = document.querySelector(window.location.hash);
if (element) {
setTimeout(() => {
const headerOffset = 80;
const elementPosition = element.offsetTop;
const offsetPosition = elementPosition - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}, 100);
}
}
}
// Initialize all functionality
document.addEventListener('DOMContentLoaded', () => {
initNavigation();
initMobileMenu();
initSmoothScroll(); |