Spaces:
Running
Running
File size: 1,521 Bytes
69014a9 | 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 | // Theme initialization
document.addEventListener('DOMContentLoaded', () => {
// Check for saved theme preference or use system preference
const savedTheme = localStorage.getItem('theme');
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (savedTheme === 'dark' || (!savedTheme && systemPrefersDark)) {
document.documentElement.classList.add('dark');
}
});
// Function to toggle theme with animation
function toggleTheme() {
const html = document.documentElement;
// Add transition class
html.classList.add('theme-transition');
// Toggle theme after short delay
setTimeout(() => {
html.classList.toggle('dark');
// Save preference to localStorage
const isDark = html.classList.contains('dark');
localStorage.setItem('theme', isDark ? 'dark' : 'light');
// Remove transition class after animation
setTimeout(() => {
html.classList.remove('theme-transition');
}, 500);
}, 50);
}
// Animate features on scroll
document.addEventListener('DOMContentLoaded', () => {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-fade-in-up');
}
});
}, { threshold: 0.1 });
document.querySelectorAll('#features .card').forEach(card => {
observer.observe(card);
});
});
|