// 表单提交处理 document.addEventListener('DOMContentLoaded', function() { const contactForm = document.querySelector('form'); if (contactForm) { contactForm.addEventListener('submit', async function(e) { e.preventDefault(); // 显示加载状态 const submitButton = this.querySelector('button[type="submit"]'); const originalText = submitButton.textContent; submitButton.innerHTML = '提交中...'; submitButton.disabled = true; // 收集表单数据 const formData = new FormData(this); const data = Object.fromEntries(formData.entries()); try { // 这里替换为您的实际API端点 const response = await fetch('/api/contact', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data) }); if (response.ok) { showNotification('提交成功!我们会尽快与您联系。', 'success'); contactForm.reset(); } else { throw new Error('提交失败'); } } catch (error) { showNotification('抱歉,提交失败,请稍后重试。', 'error'); } finally { submitButton.innerHTML = originalText; submitButton.disabled = false; } }); } }); // 页面加载动画 window.addEventListener('load', function() { const loader = document.querySelector('.page-loader'); if (loader) { loader.style.opacity = '0'; setTimeout(() => { loader.style.display = 'none'; }, 500); } }); // 导航栏交互 const mobileMenuButton = document.querySelector('.mobile-menu-button'); const mobileMenu = document.querySelector('.mobile-menu'); if (mobileMenuButton && mobileMenu) { mobileMenuButton.addEventListener('click', function() { mobileMenu.classList.toggle('hidden'); }); } // 滚动效果 window.addEventListener('scroll', function() { const nav = document.querySelector('nav'); if (window.scrollY > 100) { nav.classList.add('nav-scrolled'); } else { nav.classList.remove('nav-scrolled'); } }); // 通知提示框 function showNotification(message, type = 'success') { const notification = document.createElement('div'); notification.className = `fixed top-4 right-4 p-4 rounded-lg shadow-lg ${ type === 'success' ? 'bg-green-500' : 'bg-red-500' } text-white z-50 transform transition-all duration-300 translate-y-0`; notification.textContent = message; document.body.appendChild(notification); setTimeout(() => { notification.style.transform = 'translateY(-100%)'; setTimeout(() => { document.body.removeChild(notification); }, 300); }, 3000); } // 平滑滚动 document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); });