| document.addEventListener('DOMContentLoaded', function() { |
| |
| const tooltipTriggers = document.querySelectorAll('[data-tooltip]'); |
| tooltipTriggers.forEach(trigger => { |
| const tooltip = document.createElement('div'); |
| tooltip.className = 'hidden bg-gray-800 text-white text-xs rounded py-1 px-2 absolute z-50'; |
| tooltip.textContent = trigger.getAttribute('data-tooltip'); |
| document.body.appendChild(tooltip); |
| |
| trigger.addEventListener('mouseenter', () => { |
| const rect = trigger.getBoundingClientRect(); |
| tooltip.style.top = `${rect.top - 30}px`; |
| tooltip.style.left = `${rect.left + rect.width / 2}px`; |
| tooltip.style.transform = 'translateX(-50%)'; |
| tooltip.classList.remove('hidden'); |
| }); |
| |
| trigger.addEventListener('mouseleave', () => { |
| tooltip.classList.add('hidden'); |
| }); |
| }); |
|
|
| |
| const visitorCounter = document.getElementById('visitor-counter'); |
| if (visitorCounter) { |
| let count = Math.floor(Math.random() * 100) + 50; |
| setInterval(() => { |
| count += Math.floor(Math.random() * 3) - 1; |
| visitorCounter.textContent = count.toLocaleString() + ' Active Visitors'; |
| }, 5000); |
| } |
|
|
| |
| const forms = document.querySelectorAll('form'); |
| forms.forEach(form => { |
| form.addEventListener('submit', function(e) { |
| e.preventDefault(); |
| const submitButton = form.querySelector('button[type="submit"]'); |
| if (submitButton) { |
| const originalText = submitButton.textContent; |
| submitButton.innerHTML = '<i data-feather="loader" class="animate-spin mr-2 w-4 h-4"></i> Processing...'; |
| feather.replace(); |
| |
| |
| setTimeout(() => { |
| submitButton.textContent = originalText; |
| |
| alert('Form submitted successfully!'); |
| }, 1500); |
| } |
| }); |
| }); |
|
|
| |
| const mobileMenuButton = document.getElementById('mobile-menu-button'); |
| const mobileMenu = document.getElementById('mobile-menu'); |
| if (mobileMenuButton && mobileMenu) { |
| mobileMenuButton.addEventListener('click', () => { |
| mobileMenu.classList.toggle('hidden'); |
| }); |
| } |
|
|
| |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { |
| anchor.addEventListener('click', function(e) { |
| e.preventDefault(); |
| document.querySelector(this.getAttribute('href')).scrollIntoView({ |
| behavior: 'smooth' |
| }); |
| }); |
| }); |
|
|
| |
| feather.replace(); |
| }); |
|
|
| |
| function debounce(func, wait = 20, immediate = true) { |
| let timeout; |
| return function() { |
| const context = this, args = arguments; |
| const later = function() { |
| timeout = null; |
| if (!immediate) func.apply(context, args); |
| }; |
| const callNow = immediate && !timeout; |
| clearTimeout(timeout); |
| timeout = setTimeout(later, wait); |
| if (callNow) func.apply(context, args); |
| }; |
| } |