/
plohihilia
/
site2
Обзор
Документация
Войти
/
plohihilia
/
site2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
script.js
71 строка
3 KB
plohihilia
generate common scripts
02 мар 2026, 13:24
Верифицирован
02 мар 2026, 13:24
a20b857
Код
Авторство
О чём код?
document.addEventListener('DOMContentLoaded', function() { const burgerBtn = document.getElementById('burgerBtn'); const mainNav = document.getElementById('mainNav'); if (burgerBtn && mainNav) { burgerBtn.addEventListener('click', function() { this.classList.toggle('active'); mainNav.classList.toggle('active'); document.body.style.overflow = mainNav.classList.contains('active') ? 'hidden' : ''; }); document.querySelectorAll('.nav-link').forEach(link => { link.addEventListener('click', function() { burgerBtn.classList.remove('active'); mainNav.classList.remove('active'); document.body.style.overflow = ''; }); }); } const currentPage = window.location.pathname.split('/').pop() || 'index.html'; document.querySelectorAll('.nav-link').forEach(link => { if (link.getAttribute('href') === currentPage) { link.classList.add('active'); } }); const contactForm = document.getElementById('contactForm'); if (contactForm) { contactForm.addEventListener('submit', function(e) { e.preventDefault(); const name = document.getElementById('name'); const phone = document.getElementById('phone'); let isValid = true; [name, phone].forEach(field => { if (field) field.classList.remove('error'); }); if (name && !name.value.trim()) { name.classList.add('error'); isValid = false; } if (phone) { const phoneDigits = phone.value.replace(/\D/g, ''); if (phoneDigits.length < 10) { phone.classList.add('error'); isValid = false; } } if (isValid) { alert('Спасибо! Сообщение отправлено.'); contactForm.reset(); } else { alert('Пожалуйста, заполните все поля корректно.'); } }); } const phoneInputs = document.querySelectorAll('input[type="tel"]'); phoneInputs.forEach(input => { input.addEventListener('input', function(e) { let value = e.target.value.replace(/\D/g, ''); if (value.length > 0) { if (value.length <= 1) { value = `+7 (${value}`; } else if (value.length <= 4) { value = `+7 (${value.slice(1)}`; } else if (value.length <= 7) { value = `+7 (${value.slice(1, 4)}) ${value.slice(4)}`; } else { value = `+7 (${value.slice(1, 4)}) ${value.slice(4, 7)}-${value.slice(7, 9)}-${value.slice(9, 11)}`; } e.target.value = value; } }); }); });