55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Shrinking navbar on scroll
|
|
const navbar = document.querySelector('.navbar');
|
|
if (navbar) {
|
|
window.addEventListener('scroll', function () {
|
|
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' });
|
|
}
|
|
});
|
|
});
|
|
|
|
// Newsletter form validation
|
|
const newsletterForm = document.getElementById('newsletter-form');
|
|
const newsletterSuccess = document.getElementById('newsletter-success');
|
|
if (newsletterForm) {
|
|
newsletterForm.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
const emailInput = newsletterForm.querySelector('input[type="email"]');
|
|
if (emailInput.checkValidity()) {
|
|
// Here you would typically send the email to your server
|
|
newsletterSuccess.style.display = 'block';
|
|
emailInput.value = ''; // Clear input
|
|
setTimeout(() => { newsletterSuccess.style.display = 'none'; }, 5000);
|
|
} else {
|
|
emailInput.classList.add('is-invalid');
|
|
}
|
|
});
|
|
|
|
// Remove validation error on input
|
|
const emailInput = newsletterForm.querySelector('input[type="email"]');
|
|
if(emailInput) {
|
|
emailInput.addEventListener('input', () => {
|
|
if (emailInput.classList.contains('is-invalid')) {
|
|
emailInput.classList.remove('is-invalid');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|