Spaces:
Running
Running
| // 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' | |
| }); | |
| }); | |
| }); | |
| // Lazy loading for images | |
| document.addEventListener("DOMContentLoaded", function() { | |
| const lazyImages = [].slice.call(document.querySelectorAll("img.lazy")); | |
| if ("IntersectionObserver" in window) { | |
| let lazyImageObserver = new IntersectionObserver(function(entries, observer) { | |
| entries.forEach(function(entry) { | |
| if (entry.isIntersecting) { | |
| let lazyImage = entry.target; | |
| lazyImage.src = lazyImage.dataset.src; | |
| lazyImage.classList.remove("lazy"); | |
| lazyImageObserver.unobserve(lazyImage); | |
| } | |
| }); | |
| }); | |
| lazyImages.forEach(function(lazyImage) { | |
| lazyImageObserver.observe(lazyImage); | |
| }); | |
| } | |
| }); | |
| // Theme toggle 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'); | |
| }); | |
| } |