37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Smooth scrolling for anchor links
|
|
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
|
anchor.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
document.querySelector(this.getAttribute('href')).scrollIntoView({
|
|
behavior: 'smooth'
|
|
});
|
|
});
|
|
});
|
|
|
|
// Navbar color change on scroll
|
|
const navbar = document.querySelector('.navbar');
|
|
if (navbar) {
|
|
window.addEventListener('scroll', () => {
|
|
if (window.scrollY > 50) {
|
|
navbar.classList.add('bg-light', 'shadow');
|
|
} else {
|
|
navbar.classList.remove('bg-light', 'shadow');
|
|
}
|
|
});
|
|
}
|
|
|
|
// Form validation
|
|
const contactForm = document.getElementById('contactForm');
|
|
if(contactForm) {
|
|
contactForm.addEventListener('submit', function (event) {
|
|
if (!contactForm.checkValidity()) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
contactForm.classList.add('was-validated');
|
|
}, false);
|
|
}
|
|
});
|