mmmput's picture
Initial DeepSite commit
035b69c verified
Raw History Blame Contribute Delete
5.15 kB
// Mobile Menu Toggle
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
const navbar = document.getElementById('navbar');
// Toggle mobile menu
mobileMenuBtn.addEventListener('click', () => {
mobileMenu.classList.toggle('hidden');
const icon = mobileMenuBtn.querySelector('i');
if (mobileMenu.classList.contains('hidden')) {
icon.setAttribute('data-lucide', 'menu');
} else {
icon.setAttribute('data-lucide', 'x');
}
lucide.createIcons();
});
// Close mobile menu when clicking on a link
mobileMenu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.add('hidden');
const icon = mobileMenuBtn.querySelector('i');
icon.setAttribute('data-lucide', 'menu');
lucide.createIcons();
});
});
// Navbar scroll effect
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
// Add/remove background based on scroll position
if (currentScroll > 50) {
navbar.classList.add('shadow-md');
navbar.classList.add('bg-white/98');
} else {
navbar.classList.remove('shadow-md');
navbar.classList.remove('bg-white/98');
}
// Hide/show navbar on scroll
if (currentScroll > lastScroll && currentScroll > 100) {
navbar.style.transform = 'translateY(-100%)';
} else {
navbar.style.transform = 'translateY(0)';
}
lastScroll = currentScroll;
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offsetTop = target.offsetTop - 80; // Account for fixed header
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// Intersection Observer for fade-in animations
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe elements with animation classes
document.querySelectorAll('.group').forEach((el) => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease-out, transform 0.6s ease-out';
observer.observe(el);
});
// Form submission handler
document.querySelector('form').addEventListener('submit', (e) => {
e.preventDefault();
// Show success message
const button = e.target.querySelector('button');
const originalText = button.textContent;
button.innerHTML = '<i data-lucide="check" class="w-5 h-5 inline mr-2"></i> Message Sent!';
button.classList.remove('bg-green-600', 'hover:bg-green-700');
button.classList.add('bg-blue-600');
lucide.createIcons();
// Reset form
e.target.reset();
// Reset button after 3 seconds
setTimeout(() => {
button.textContent = originalText;
button.classList.add('bg-green-600', 'hover:bg-green-700');
button.classList.remove('bg-blue-600');
}, 3000);
});
// Counter animation for stats
function animateValue(obj, start, end, duration) {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
obj.innerHTML = Math.floor(progress * (end - start) + start);
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
}
// Initialize counters when in view
const statsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = entry.target;
const endValue = parseInt(target.getAttribute('data-target'));
animateValue(target, 0, endValue, 2000);
statsObserver.unobserve(target);
}
});
}, { threshold: 0.5 });
// Add to stat elements if needed
document.querySelectorAll('.stat-counter').forEach(stat => {
statsObserver.observe(stat);
});
// Add hover effect to tournament cards
document.querySelectorAll('.tournament-card').forEach(card => {
card.addEventListener('mouseenter', () => {
card.classList.add('scale-[1.02]');
});
card.addEventListener('mouseleave', () => {
card.classList.remove('scale-[1.02]');
});
});
// console log welcome message
console.log('%c🎾 Welcome to Ace Tennis Club!', 'color: #10b981; font-size: 20px; font-weight: bold;');
console.log('%cProfessional tennis website template', 'color: #6b7280; font-size: 12px;');