| |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { |
| anchor.addEventListener('click', function (e) { |
| e.preventDefault(); |
| document.querySelector(this.getAttribute('href')).scrollIntoView({ |
| behavior: 'smooth' |
| }); |
| }); |
| }); |
|
|
| |
| 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); |
|
|
| |
| 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'); |
| }); |
| } |
|
|
| |
| if (localStorage.getItem('theme') === 'light') { |
| document.documentElement.classList.remove('dark'); |
| } else { |
| document.documentElement.classList.add('dark'); |
| } |
| |
| document.addEventListener('DOMContentLoaded', () => { |
| |
| 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'); |
| } |
| }); |
| |
| |
| if (document.querySelector('.code-editor')) { |
| |
| console.log('Code editor initialized'); |
| } |
| }); |
|
|