File size: 7,116 Bytes
f89ea03 | 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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | // Counter Animation
const counters = document.querySelectorAll('.counter');
const speed = 200;
const countUp = () => {
counters.forEach(counter => {
const target = +counter.getAttribute('data-target');
const count = +counter.innerText;
const increment = target / speed;
if (count < target) {
counter.innerText = Math.ceil(count + increment);
setTimeout(countUp, 10);
} else {
counter.innerText = target;
}
});
};
// Intersection Observer for Counter Animation
const observerOptions = {
threshold: 0.5,
rootMargin: '0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
countUp();
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe stats section
const statsSection = document.querySelector('.counter');
if (statsSection) {
observer.observe(statsSection.parentElement);
}
// Form Handling
const contactForm = document.getElementById('contactForm');
const formMessage = document.getElementById('formMessage');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Show loading state
const submitButton = contactForm.querySelector('button[type="submit"]');
const originalText = submitButton.textContent;
submitButton.innerHTML = '<span class="spinner inline-block w-4 h-4 mr-2"></span>Sending...';
submitButton.disabled = true;
// Simulate form submission
setTimeout(() => {
// Show success message
formMessage.textContent = 'Thank you for your message! We will get back to you soon.';
formMessage.className = 'message-success';
formMessage.classList.remove('hidden');
// Reset form
contactForm.reset();
// Reset button
submitButton.textContent = originalText;
submitButton.disabled = false;
// Hide message after 5 seconds
setTimeout(() => {
formMessage.classList.add('hidden');
}, 5000);
}, 2000);
});
}
// FAQ Toggle
const faqToggles = document.querySelectorAll('.faq-toggle');
faqToggles.forEach(toggle => {
toggle.addEventListener('click', () => {
const content = toggle.nextElementSibling;
const icon = toggle.querySelector('i');
// Toggle current item
content.classList.toggle('show');
toggle.classList.toggle('active');
// Close other items
faqToggles.forEach(otherToggle => {
if (otherToggle !== toggle) {
const otherContent = otherToggle.nextElementSibling;
const otherIcon = otherToggle.querySelector('i');
otherContent.classList.remove('show');
otherToggle.classList.remove('active');
}
});
});
});
// 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) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Mobile Menu (if needed)
const mobileMenuButton = document.querySelector('.mobile-menu-button');
const mobileMenu = document.querySelector('.mobile-menu');
if (mobileMenuButton && mobileMenu) {
mobileMenuButton.addEventListener('click', () => {
mobileMenu.classList.toggle('active');
});
}
// Scroll to Top Button
const scrollToTopBtn = document.createElement('button');
scrollToTopBtn.innerHTML = '<i data-feather="arrow-up"></i>';
scrollToTopBtn.className = 'fixed bottom-8 right-8 bg-blue-600 text-white p-3 rounded-full shadow-lg hover:bg-blue-700 transition-all z-50 hidden';
document.body.appendChild(scrollToTopBtn);
window.addEventListener('scroll', () => {
if (window.pageYOffset > 300) {
scrollToTopBtn.classList.remove('hidden');
} else {
scrollToTopBtn.classList.add('hidden');
}
});
scrollToTopBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// Re-initialize Feather icons after dynamic content
feather.replace();
// Parallax Effect for Hero Section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const parallaxElements = document.querySelectorAll('.parallax');
parallaxElements.forEach(element => {
const speed = element.dataset.speed || 0.5;
element.style.transform = `translateY(${scrolled * speed}px)`;
});
});
// Add active nav state based on current page
const currentPath = window.location.pathname;
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
if (link.getAttribute('href') === currentPath ||
(currentPath === '/' && link.getAttribute('href') === 'index.html')) {
link.classList.add('active');
}
});
// Lazy Loading for Images
const images = document.querySelectorAll('img[data-src]');
const imageOptions = {
threshold: 0,
rootMargin: '0px 0px 50px 0px'
};
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('lazy');
imageObserver.unobserve(img);
}
});
}, imageOptions);
images.forEach(img => imageObserver.observe(img));
// Initialize Tooltips (if needed)
const tooltips = document.querySelectorAll('[data-tooltip]');
tooltips.forEach(element => {
element.addEventListener('mouseenter', (e) => {
const tooltip = document.createElement('div');
tooltip.className = 'absolute bg-gray-800 text-white text-sm px-2 py-1 rounded z-50';
tooltip.textContent = e.target.dataset.tooltip;
document.body.appendChild(tooltip);
const rect = e.target.getBoundingClientRect();
tooltip.style.left = rect.left + (rect.width / 2) - (tooltip.offsetWidth / 2) + 'px';
tooltip.style.top = rect.top - tooltip.offsetHeight - 5 + 'px';
e.target.addEventListener('mouseleave', () => {
tooltip.remove();
}, { once: true });
});
});
// Performance optimization: Debounce function
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Debounced resize handler
const debouncedResize = debounce(() => {
// Handle resize events
feather.replace();
}, 250);
window.addEventListener('resize', debouncedResize); |