Flatlogic Bot 8d45670c2f Ver 1
2025-09-10 20:32:30 +00:00

65 lines
2.3 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function () {
const navbar = document.querySelector('.navbar');
const contactForm = document.querySelector('#contactForm');
// Navbar shrink on scroll
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if(targetElement){
targetElement.scrollIntoView({ behavior: 'smooth' });
}
});
});
// Basic form validation
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
let isValid = true;
const name = document.getElementById('name');
const email = document.getElementById('email');
const message = document.getElementById('message');
// Reset validation
[name, email, message].forEach(el => {
el.classList.remove('is-invalid');
});
if (name.value.trim() === '') {
name.classList.add('is-invalid');
isValid = false;
}
if (!/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(email.value)) {
email.classList.add('is-invalid');
isValid = false;
}
if (message.value.trim() === '') {
message.classList.add('is-invalid');
isValid = false;
}
if (isValid) {
// On a real site, you'd send this data to the server.
// For this demo, we'll just show a success message.
document.querySelector('#form-feedback').innerHTML = '<div class="alert alert-success">Thank you for your message! We will get back to you shortly.</div>';
contactForm.reset();
} else {
document.querySelector('#form-feedback').innerHTML = '';
}
});
}
});