34669-vm/assets/js/main.js
Flatlogic Bot 6db56c92fb 1.1
2025-10-04 18:38:46 +00:00

51 lines
1.9 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function () {
// Navbar shrink function
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('bg-white', 'shadow-sm');
} else {
navbar.classList.remove('bg-white', 'shadow-sm');
}
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Contact form validation
const contactForm = document.getElementById('contactForm');
contactForm.addEventListener('submit', function (e) {
e.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
if (name === '' || email === '' || message === '') {
alert('Please fill in all fields.');
return;
}
if (!validateEmail(email)) {
alert('Please enter a valid email address.');
return;
}
// If validation passes, you would typically send the form data to the server here.
// For this example, we'll just show a success message.
this.style.display = 'none';
document.getElementById('formSuccess').style.display = 'block';
});
function validateEmail(email) {
const re = /^(([^<>()[\\]\\.,;:\s@"]+(\.[^<>()[\\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
});