govmail-simulator / script.js
large000's picture
i need you to create a website for secondary school
6f707ff verified
Raw History Blame Contribute Delete
2.4 kB
// Mobile menu toggle
document.addEventListener('DOMContentLoaded', function() {
// Mobile menu functionality
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
if (mobileMenuBtn) {
mobileMenuBtn.addEventListener('click', function() {
const navLinks = document.querySelector('.nav-links');
navLinks.style.display = navLinks.style.display === 'flex' ? 'none' : 'flex';
});
}
// 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'
});
});
});
// Current year for copyright
document.getElementById('current-year').textContent = new Date().getFullYear();
});
// Image gallery functionality
function initImageGallery() {
const galleryImages = document.querySelectorAll('.gallery-image');
const lightbox = document.getElementById('lightbox');
const lightboxImg = document.getElementById('lightbox-img');
const closeBtn = document.querySelector('.lightbox-close');
galleryImages.forEach(img => {
img.addEventListener('click', () => {
lightbox.style.display = 'flex';
lightboxImg.src = img.src;
});
});
closeBtn.addEventListener('click', () => {
lightbox.style.display = 'none';
});
lightbox.addEventListener('click', (e) => {
if (e.target === lightbox) {
lightbox.style.display = 'none';
}
});
}
// Form validation
function validateForm(formId) {
const form = document.getElementById(formId);
if (form) {
form.addEventListener('submit', function(e) {
let isValid = true;
const requiredFields = form.querySelectorAll('[required]');
requiredFields.forEach(field => {
if (!field.value.trim()) {
isValid = false;
field.classList.add('error');
} else {
field.classList.remove('error');
}
});
if (!isValid) {
e.preventDefault();
alert('Please fill in all required fields.');
}
});
}
}