File size: 4,126 Bytes
3b53676 | 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 | // Main JavaScript for FleetFlex Pro Solutions
// Initialize Feather Icons
document.addEventListener('DOMContentLoaded', function() {
if (typeof feather !== 'undefined') {
feather.replace();
}
// Add smooth scrolling 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'
});
}
});
});
// Add intersection observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in-up');
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe all sections for animation
document.querySelectorAll('section').forEach(section => {
observer.observe(section);
});
// Stats counter animation
const statsSection = document.querySelector('.bg-white');
const statsObserver = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
animateStats();
statsObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
if (statsSection) {
statsObserver.observe(statsSection);
}
});
// Animate statistics counters
function animateStats() {
const counters = document.querySelectorAll('.text-4xl');
const speed = 200; // The lower the slower
counters.forEach(counter => {
const target = +counter.innerText.replace(',', '');
const increment = target / speed;
let current = 0;
const updateCount = () => {
current += increment;
if (current < target) {
counter.innerText = Math.floor(current).toLocaleString();
setTimeout(updateCount, 1);
} else {
counter.innerText = target.toLocaleString();
}
};
updateCount();
});
}
// Handle form submissions
function handleContactForm(event) {
event.preventDefault();
// Show loading state
const submitBtn = event.target.querySelector('button[type="submit"]');
const originalText = submitBtn.innerHTML;
submitBtn.innerHTML = '<div class="loading-dots"><div></div><div></div><div></div><div></div></div>';
// Simulate API call
setTimeout(() => {
submitBtn.innerHTML = originalText;
alert('Thank you for your message! We will get back to you soon.');
event.target.reset();
}, 2000);
}
// Mobile menu toggle functionality
function toggleMobileMenu() {
const mobileMenu = document.getElementById('mobile-menu');
if (mobileMenu) {
mobileMenu.classList.toggle('hidden');
}
}
// Add scroll effect to header
window.addEventListener('scroll', function() {
const header = document.querySelector('custom-header');
if (header && header.shadowRoot) {
const headerElement = header.shadowRoot.querySelector('header');
if (window.scrollY > 100) {
headerElement.classList.add('bg-white', 'shadow-lg');
headerElement.classList.remove('bg-transparent');
} else {
headerElement.classList.remove('bg-white', 'shadow-lg');
headerElement.classList.add('bg-transparent');
}
}
});
// Initialize any third-party APIs if needed
function initializeExternalAPIs() {
// Placeholder for any external API integrations
console.log('External APIs initialized');
}
// Export functions for use in components if needed
window.FleetFlex = {
toggleMobileMenu,
handleContactForm,
animateStats
}; |