Spaces:
Running

autofuchsia-masters / script.js
snw321's picture
Роль: Ты — профессиональный веб-разработчик и UX/UI дизайнер с опытом создания сайтов для автомобильного бизнеса. Твоя задача — спроектировать и создать многостраничный сайт для автосервиса "Название_Вашего_Сервиса".
7661b1c verified
Raw History Blame Contribute Delete
2.54 kB
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
}
});
});
// Mobile menu toggle functionality
document.addEventListener('DOMContentLoaded', () => {
const mobileMenuButton = document.querySelector('[data-mobile-menu-button]');
const mobileMenu = document.querySelector('[data-mobile-menu]');
if (mobileMenuButton && mobileMenu) {
mobileMenuButton.addEventListener('click', () => {
const isExpanded = mobileMenuButton.getAttribute('aria-expanded') === 'true';
mobileMenuButton.setAttribute('aria-expanded', !isExpanded);
mobileMenu.classList.toggle('hidden');
// Toggle icon
const icon = mobileMenuButton.querySelector('svg');
if (icon) {
if (isExpanded) {
icon.setAttribute('data-feather', 'menu');
} else {
icon.setAttribute('data-feather', 'x');
}
feather.replace();
}
});
}
// Initialize feather icons
feather.replace();
// Form submission handling
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(form);
const submitButton = form.querySelector('button[type="submit"]');
const originalText = submitButton.textContent;
// Show loading state
submitButton.disabled = true;
submitButton.innerHTML = '<i data-feather="loader" class="animate-spin mr-2"></i> Отправка...';
feather.replace();
try {
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 1500));
// Show success message
const successMessage = document.createElement('div');
successMessage.className = 'mt-4 p-4 bg-green-500/20 text-green-500