ideaforge-nexus / script.js
Cupofjavad's picture
Completely redesign, enhance, and improve my site. Use the below notes to add to the site as well:
f4f0cff verified
Raw History Blame Contribute Delete
1.56 kB
document.addEventListener('DOMContentLoaded', function() {
// Dark mode toggle functionality
const darkModeToggle = document.getElementById('darkModeToggle');
if (darkModeToggle) {
darkModeToggle.addEventListener('click', function() {
document.documentElement.classList.toggle('dark');
localStorage.setItem('darkMode', document.documentElement.classList.contains('dark'));
});
// Check for saved user preference
if (localStorage.getItem('darkMode') === 'true') {
document.documentElement.classList.add('dark');
}
}
// 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'
});
});
});
// Add fade-in animations to elements
const animatedElements = document.querySelectorAll('.fade-in');
animatedElements.forEach((el, index) => {
el.style.opacity = '0';
el.classList.add(`delay-${(index % 3 + 1) * 100}`);
});
// Intersection Observer for scroll animations
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
}
});
}, { threshold: 0.1 });
animatedElements.forEach(el => observer.observe(el));
});