Spaces:
Running
Running
File size: 5,145 Bytes
035b69c | 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 | // 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;'); |