HYGHYN's picture
Clone website 100% Clone no modified
f89ea03 verified
Raw History Blame Contribute Delete
7.12 kB
// 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);