Spaces:
Running
Running
| // Shared functions and utilities | |
| // Debounce function for resize events | |
| function debounce(func, wait = 100) { | |
| let timeout; | |
| return function(...args) { | |
| clearTimeout(timeout); | |
| timeout = setTimeout(() => { | |
| func.apply(this, args); | |
| }, wait); | |
| }; | |
| } | |
| // Check if element is in viewport | |
| function isInViewport(element) { | |
| const rect = element.getBoundingClientRect(); | |
| return ( | |
| rect.top >= 0 && | |
| rect.left >= 0 && | |
| rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | |
| rect.right <= (window.innerWidth || document.documentElement.clientWidth) | |
| ); | |
| } | |
| // Add smooth scrolling to all links | |
| document.addEventListener('DOMContentLoaded', () => { | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| document.querySelector(this.getAttribute('href')).scrollIntoView({ | |
| behavior: 'smooth' | |
| }); | |
| }); | |
| }); | |
| }); | |
| // Handle back to top button | |
| window.addEventListener('scroll', debounce(() => { | |
| const backToTop = document.getElementById('back-to-top'); | |
| if (backToTop) { | |
| if (window.pageYOffset > 300) { | |
| backToTop.classList.remove('opacity-0', 'invisible'); | |
| backToTop.classList.add('opacity-100', 'visible'); | |
| } else { | |
| backToTop.classList.remove('opacity-100', 'visible'); | |
| backToTop.classList.add('opacity-0', 'invisible'); | |
| } | |
| } | |
| })); |