File size: 2,096 Bytes
bff980a 6f00a0c bff980a 6f00a0c bff980a 6f00a0c bff980a 6f00a0c | 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 | // 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'
});
});
});
// Initialize animations on scroll
const animateOnScroll = () => {
const elements = document.querySelectorAll('.fade-in, .slide-up');
elements.forEach(element => {
const elementPosition = element.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (elementPosition < windowHeight - 100) {
element.style.opacity = '1';
element.style.transform = 'translateY(0)';
}
});
};
window.addEventListener('scroll', animateOnScroll);
window.addEventListener('load', animateOnScroll);
// Theme switcher functionality
const themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', () => {
document.documentElement.classList.toggle('dark');
localStorage.setItem('theme', document.documentElement.classList.contains('dark') ? 'dark' : 'light');
});
}
// Check for saved theme preference
if (localStorage.getItem('theme') === 'light') {
document.documentElement.classList.remove('dark');
} else {
document.documentElement.classList.add('dark');
}
// CodeDex specific initialization
document.addEventListener('DOMContentLoaded', () => {
// Add active class to current nav link
const currentPath = window.location.pathname;
const navLinks = document.querySelectorAll('custom-navbar a, custom-footer a');
navLinks.forEach(link => {
if (link.getAttribute('href') === currentPath) {
link.classList.add('active');
}
});
// Initialize code editor if present
if (document.querySelector('.code-editor')) {
// This would be replaced with actual CodeMirror or Monaco editor initialization
console.log('Code editor initialized');
}
});
|