init
This commit is contained in:
98
js/main.js
Normal file
98
js/main.js
Normal file
@@ -0,0 +1,98 @@
|
||||
// ===== Mobile Menu =====
|
||||
const hamburger = document.getElementById('hamburger');
|
||||
const mobileNav = document.getElementById('mobileNav');
|
||||
const mobileNavClose = document.getElementById('mobileNavClose');
|
||||
const mobileNavLinks = mobileNav.querySelectorAll('a');
|
||||
|
||||
hamburger.addEventListener('click', () => {
|
||||
mobileNav.classList.add('active');
|
||||
document.body.style.overflow = 'hidden';
|
||||
});
|
||||
|
||||
mobileNavClose.addEventListener('click', closeMobileNav);
|
||||
|
||||
mobileNavLinks.forEach(link => {
|
||||
link.addEventListener('click', closeMobileNav);
|
||||
});
|
||||
|
||||
function closeMobileNav() {
|
||||
mobileNav.classList.remove('active');
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
|
||||
// ===== Contact Form =====
|
||||
const contactForm = document.getElementById('contactForm');
|
||||
const formSuccess = document.getElementById('formSuccess');
|
||||
|
||||
contactForm.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
// Clear previous errors
|
||||
document.querySelectorAll('.form-error').forEach(el => el.style.display = 'none');
|
||||
|
||||
const name = document.getElementById('formName');
|
||||
const email = document.getElementById('formEmail');
|
||||
const phone = document.getElementById('formPhone');
|
||||
const message = document.getElementById('formMessage');
|
||||
|
||||
let valid = true;
|
||||
|
||||
if (!name.value.trim()) {
|
||||
showError(name, 'Prosím vyplňte své jméno');
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!email.value.trim() || !isValidEmail(email.value)) {
|
||||
showError(email, 'Prosím zadejte platný e-mail');
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!phone.value.trim()) {
|
||||
showError(phone, 'Prosím zadejte telefonní číslo');
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!message.value.trim()) {
|
||||
showError(message, 'Prosím napište zprávu');
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!valid) return;
|
||||
|
||||
// Hide form, show success
|
||||
contactForm.style.display = 'none';
|
||||
formSuccess.style.display = 'block';
|
||||
});
|
||||
|
||||
function showError(input, msg) {
|
||||
const errorEl = input.parentElement.querySelector('.form-error');
|
||||
if (errorEl) {
|
||||
errorEl.textContent = msg;
|
||||
errorEl.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
function isValidEmail(email) {
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
||||
}
|
||||
|
||||
// ===== Smooth Scroll for "Objednat se" buttons =====
|
||||
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
||||
anchor.addEventListener('click', (e) => {
|
||||
const target = document.querySelector(anchor.getAttribute('href'));
|
||||
if (target) {
|
||||
e.preventDefault();
|
||||
target.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ===== Header shadow on scroll =====
|
||||
const header = document.querySelector('.header');
|
||||
window.addEventListener('scroll', () => {
|
||||
if (window.scrollY > 10) {
|
||||
header.style.boxShadow = '0 2px 12px rgba(0,0,0,.08)';
|
||||
} else {
|
||||
header.style.boxShadow = 'none';
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user