41 lines
1.3 KiB
JavaScript
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 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 feedback
|
|
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);
|
|
}
|
|
});
|