File size: 3,122 Bytes
a0550f9 a71d5c8 a0550f9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | // Theme toggle functionality
document.addEventListener('DOMContentLoaded', function() {
// Check for saved theme preference or use preferred color scheme
const savedTheme = localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
// Apply the saved theme
document.documentElement.classList.add(savedTheme);
localStorage.setItem('theme', savedTheme);
// Update the toggle button state
updateThemeToggle(savedTheme);
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
});
});
});
// Function to update theme toggle button
function updateThemeToggle(theme) {
const toggleBtn = document.querySelector('.theme-toggle');
if (toggleBtn) {
if (theme === 'dark') {
toggleBtn.innerHTML = '<i data-feather="sun"></i>';
} else {
toggleBtn.innerHTML = '<i data-feather="moon"></i>';
}
// Initialize feather icons
document.addEventListener('DOMContentLoaded', function() {
feather.replace();
// Scroll reveal animation
const sr = ScrollReveal({
origin: 'bottom',
distance: '60px',
duration: 1000,
delay: 200,
reset: true
});
sr.reveal('.mission-item', {
interval: 200,
origin: 'bottom',
distance: '40px'
});
});
}
}
// Function to toggle between light and dark theme
function toggleTheme() {
const html = document.documentElement;
const currentTheme = localStorage.getItem('theme') || 'light';
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
html.classList.remove(currentTheme);
html.classList.add(newTheme);
localStorage.setItem('theme', newTheme);
updateThemeToggle(newTheme);
}
// Form submission handling
document.querySelector('form')?.addEventListener('submit', function(e) {
e.preventDefault();
// Get form values
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const subject = document.getElementById('subject').value;
const message = document.getElementById('message').value;
// Simple validation
if (!name || !email || !message) {
alert('Please fill in all required fields.');
return;
}
// Here you would typically send the form data to a server
console.log('Form submitted:', { name, email, subject, message });
// Show success message
alert('Thank you for your message! We will get back to you soon.');
// Reset form
this.reset();
}); |