// Back to Top Button functionality let backToTopBtn; function handleScroll() { if (window.pageYOffset > 300) { backToTopBtn.classList.remove('opacity-0', 'invisible'); backToTopBtn.classList.add('opacity-100', 'visible'); } else { backToTopBtn.classList.remove('opacity-100', 'visible'); backToTopBtn.classList.add('opacity-0', 'invisible'); } } function scrollToTop() { window.scrollTo({ top: 0, behavior: 'smooth' }); } export function init() { // Initialize back to top button backToTopBtn = document.getElementById('backToTopBtn'); if (backToTopBtn) { // Show/hide button based on scroll position window.addEventListener('scroll', handleScroll); // Add click event listener backToTopBtn.addEventListener('click', scrollToTop); // Initial check handleScroll(); } } export function teardown() { if (backToTopBtn) { window.removeEventListener('scroll', handleScroll); backToTopBtn.removeEventListener('click', scrollToTop); } }