104 lines
3.1 KiB
JavaScript
104 lines
3.1 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
// Check for reduced motion preference
|
|
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
// Intersection Observer for reveal animations
|
|
if (!prefersReducedMotion) {
|
|
const revealElements = document.querySelectorAll('[data-reveal]');
|
|
|
|
const revealObserver = new IntersectionObserver((entries) => {
|
|
entries.forEach((entry) => {
|
|
if (entry.isIntersecting) {
|
|
const index = parseInt(entry.target.dataset.revealIndex, 10) || 0;
|
|
const delay = index * 100;
|
|
setTimeout(() => {
|
|
entry.target.classList.add('revealed');
|
|
}, delay);
|
|
revealObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1,
|
|
rootMargin: '0px 0px -50px 0px'
|
|
});
|
|
|
|
revealElements.forEach(el => {
|
|
revealObserver.observe(el);
|
|
});
|
|
|
|
// Service cards reveal
|
|
const serviceCards = document.querySelectorAll('.service-card');
|
|
const cardObserver = new IntersectionObserver((entries) => {
|
|
entries.forEach((entry) => {
|
|
if (entry.isIntersecting) {
|
|
const index = parseInt(entry.target.dataset.revealIndex, 10) || 0;
|
|
setTimeout(() => {
|
|
entry.target.classList.add('revealed');
|
|
}, index * 100);
|
|
cardObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1,
|
|
rootMargin: '0px 0px -30px 0px'
|
|
});
|
|
|
|
serviceCards.forEach(card => {
|
|
cardObserver.observe(card);
|
|
});
|
|
} else {
|
|
// If reduced motion, show everything immediately
|
|
document.querySelectorAll('[data-reveal], .service-card').forEach(el => {
|
|
el.classList.add('revealed');
|
|
});
|
|
}
|
|
|
|
// Smooth scroll for anchor links
|
|
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
|
anchor.addEventListener('click', function(e) {
|
|
const targetId = this.getAttribute('href');
|
|
if (targetId === '#') return;
|
|
|
|
const targetElement = document.querySelector(targetId);
|
|
if (targetElement) {
|
|
e.preventDefault();
|
|
const header = document.querySelector('.site-header');
|
|
const headerHeight = header ? header.offsetHeight : 0;
|
|
const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - headerHeight - 20;
|
|
|
|
window.scrollTo({
|
|
top: targetPosition,
|
|
behavior: prefersReducedMotion ? 'auto' : 'smooth'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Header shadow on scroll
|
|
const header = document.querySelector('.site-header');
|
|
let lastScroll = 0;
|
|
|
|
const handleScroll = () => {
|
|
const currentScroll = window.pageYOffset;
|
|
|
|
if (currentScroll > 100) {
|
|
header.style.boxShadow = 'var(--shadow-md)';
|
|
} else {
|
|
header.style.boxShadow = 'none';
|
|
}
|
|
|
|
lastScroll = currentScroll;
|
|
};
|
|
|
|
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
|
|
// Animate drops with varied timing
|
|
if (!prefersReducedMotion) {
|
|
const drops = document.querySelectorAll('.drop');
|
|
drops.forEach((drop, i) => {
|
|
drop.style.animationDelay = `${i * 1.2}s`;
|
|
});
|
|
}
|
|
})(); |