Files
site-55ea8/script.js
T
2026-07-30 17:05:48 +00:00

180 lines
5.4 KiB
JavaScript

(function() {
'use strict';
// Respect reduced motion preference
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// Cursor glow effect (only on devices with fine pointer)
const cursorGlow = document.querySelector('.cursor-glow');
const hasFinePointer = window.matchMedia('(pointer: fine)').matches;
if (cursorGlow && !prefersReducedMotion && hasFinePointer) {
let mouseX = 0, mouseY = 0;
let glowX = 0, glowY = 0;
let rafId = null;
document.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
function animateCursor() {
glowX += (mouseX - glowX) * 0.1;
glowY += (mouseY - glowY) * 0.1;
cursorGlow.style.left = glowX + 'px';
cursorGlow.style.top = glowY + 'px';
rafId = requestAnimationFrame(animateCursor);
}
animateCursor();
// Cleanup on page hide
document.addEventListener('visibilitychange', () => {
if (document.hidden && rafId) {
cancelAnimationFrame(rafId);
} else if (!document.hidden) {
animateCursor();
}
});
}
// Header scroll effect
const header = document.querySelector('.site-header');
let ticking = false;
function handleScroll() {
if (!ticking) {
requestAnimationFrame(() => {
const currentScrollY = window.scrollY;
if (currentScrollY > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
ticking = false;
});
ticking = true;
}
}
window.addEventListener('scroll', handleScroll, { passive: true });
// Mobile navigation
const navToggle = document.querySelector('.nav-toggle');
const navLinks = document.querySelector('.nav-links');
if (navToggle && navLinks) {
navToggle.addEventListener('click', () => {
const isExpanded = navToggle.getAttribute('aria-expanded') === 'true';
navToggle.setAttribute('aria-expanded', !isExpanded);
navLinks.classList.toggle('active');
document.body.style.overflow = isExpanded ? '' : 'hidden';
// Update label
navToggle.setAttribute('aria-label', isExpanded ? 'פתיחת תפריט ניווט' : 'סגירת תפריט ניווט');
});
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navToggle.setAttribute('aria-expanded', 'false');
navToggle.setAttribute('aria-label', 'פתיחת תפריט ניווט');
navLinks.classList.remove('active');
document.body.style.overflow = '';
});
});
// Close on escape
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && navLinks.classList.contains('active')) {
navToggle.setAttribute('aria-expanded', 'false');
navToggle.setAttribute('aria-label', 'פתיחת תפריט ניווט');
navLinks.classList.remove('active');
document.body.style.overflow = '';
navToggle.focus();
}
});
}
// Reveal on scroll
const revealElements = document.querySelectorAll('.reveal');
if (!prefersReducedMotion && revealElements.length > 0) {
const observerOptions = {
root: null,
rootMargin: '0px 0px -80px 0px',
threshold: 0.1
};
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
}, observerOptions);
revealElements.forEach(el => revealObserver.observe(el));
} else {
revealElements.forEach(el => el.classList.add('visible'));
}
// Form submission
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
const btn = contactForm.querySelector('.btn');
const btnText = btn.querySelector('span');
const originalText = btnText.textContent;
// Basic validation
const name = contactForm.querySelector('#name');
const email = contactForm.querySelector('#email');
if (!name.value.trim() || !email.value.trim()) {
return;
}
// Disable button
btn.disabled = true;
btnText.textContent = 'שולח...';
// Simulate send (replace with actual form handling)
setTimeout(() => {
btnText.textContent = 'נשלח בהצלחה! ✓';
btn.style.background = 'linear-gradient(135deg, #00b894 0%, #55efc4 100%)';
setTimeout(() => {
btnText.textContent = originalText;
btn.style.background = '';
btn.disabled = false;
contactForm.reset();
}, 3000);
}, 1000);
});
}
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', (e) => {
const href = anchor.getAttribute('href');
if (href === '#') return;
const target = document.querySelector(href);
if (target) {
e.preventDefault();
target.scrollIntoView({
behavior: prefersReducedMotion ? 'auto' : 'smooth'
});
// Set focus for accessibility
target.setAttribute('tabindex', '-1');
target.focus({ preventScroll: true });
}
});
});
})();