121 lines
3.6 KiB
JavaScript
121 lines
3.6 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
// Respect reduced motion preference
|
|
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
// Mobile menu toggle
|
|
const menuToggle = document.querySelector('.menu-toggle');
|
|
const mainNav = document.querySelector('.main-nav');
|
|
const navOverlay = document.querySelector('.nav-overlay');
|
|
|
|
function closeMenu() {
|
|
menuToggle.setAttribute('aria-expanded', 'false');
|
|
menuToggle.classList.remove('active');
|
|
mainNav.classList.remove('active');
|
|
navOverlay.classList.remove('active');
|
|
document.body.style.overflow = '';
|
|
}
|
|
|
|
function openMenu() {
|
|
menuToggle.setAttribute('aria-expanded', 'true');
|
|
menuToggle.classList.add('active');
|
|
mainNav.classList.add('active');
|
|
navOverlay.classList.add('active');
|
|
document.body.style.overflow = 'hidden';
|
|
}
|
|
|
|
if (menuToggle && mainNav && navOverlay) {
|
|
menuToggle.addEventListener('click', function() {
|
|
const isExpanded = this.getAttribute('aria-expanded') === 'true';
|
|
if (isExpanded) {
|
|
closeMenu();
|
|
} else {
|
|
openMenu();
|
|
}
|
|
});
|
|
|
|
// Close menu when clicking on a link
|
|
mainNav.querySelectorAll('a').forEach(link => {
|
|
link.addEventListener('click', closeMenu);
|
|
});
|
|
|
|
// Close menu when clicking overlay
|
|
navOverlay.addEventListener('click', closeMenu);
|
|
|
|
// Close menu on escape key
|
|
document.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Escape' && mainNav.classList.contains('active')) {
|
|
closeMenu();
|
|
menuToggle.focus();
|
|
}
|
|
});
|
|
}
|
|
|
|
// Reveal on scroll with IntersectionObserver
|
|
if (!prefersReducedMotion) {
|
|
const revealElements = document.querySelectorAll('.reveal');
|
|
let revealDelay = 0;
|
|
|
|
const revealObserver = new IntersectionObserver((entries) => {
|
|
entries.forEach((entry) => {
|
|
if (entry.isIntersecting) {
|
|
setTimeout(() => {
|
|
entry.target.classList.add('visible');
|
|
}, revealDelay);
|
|
revealDelay += 80;
|
|
setTimeout(() => { revealDelay = 0; }, 500);
|
|
revealObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1,
|
|
rootMargin: '0px 0px -50px 0px'
|
|
});
|
|
|
|
revealElements.forEach(el => revealObserver.observe(el));
|
|
} else {
|
|
// If reduced motion is preferred, show all elements immediately
|
|
document.querySelectorAll('.reveal').forEach(el => {
|
|
el.classList.add('visible');
|
|
});
|
|
}
|
|
|
|
// Header scroll effect
|
|
const header = document.querySelector('.site-header');
|
|
|
|
window.addEventListener('scroll', function() {
|
|
const currentScroll = window.pageYOffset;
|
|
|
|
if (currentScroll > 100) {
|
|
header.style.boxShadow = '0 4px 20px rgba(44, 24, 16, 0.1)';
|
|
} else {
|
|
header.style.boxShadow = 'none';
|
|
}
|
|
}, { passive: true });
|
|
|
|
// Smooth scroll for anchor links
|
|
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
|
anchor.addEventListener('click', function(e) {
|
|
const href = this.getAttribute('href');
|
|
if (href === '#') return;
|
|
|
|
const target = document.querySelector(href);
|
|
if (target) {
|
|
e.preventDefault();
|
|
const headerHeight = header.offsetHeight;
|
|
const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - headerHeight - 20;
|
|
|
|
window.scrollTo({
|
|
top: targetPosition,
|
|
behavior: prefersReducedMotion ? 'auto' : 'smooth'
|
|
});
|
|
|
|
// Set focus to the target for accessibility
|
|
target.setAttribute('tabindex', '-1');
|
|
target.focus({ preventScroll: true });
|
|
}
|
|
});
|
|
});
|
|
|
|
})(); |