33957-vm/assets/js/main.js
Flatlogic Bot 17002c92f7 v2
2025-09-10 05:03:19 +00:00

41 lines
1.3 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function () {
// Navbar shrink on scroll
const navbar = document.querySelector('.navbar-sticky');
if (navbar) {
const handleScroll = () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
};
window.addEventListener('scroll', handleScroll);
handleScroll(); // Initial check
}
// Smooth scroll 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' });
}
});
});
// Client-side form validation
const form = document.querySelector('.needs-validation');
if (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
}
});