(function () { // Check if body-container exists const bodyContainer = document.querySelector('.body-container'); if (!bodyContainer) return; // Prevent duplicates if (document.querySelector('#backToTopBtn')) return; // Create button const btn = document.createElement('button'); btn.id = 'backToTopBtn'; // Insert custom SVG arrow with horizontal line, moved down slightly btn.innerHTML = ` `; // Initial styling Object.assign(btn.style, { position: 'fixed', zIndex: '9999', width: '50px', height: '50px', lineHeight: '50px', textAlign: 'center', textDecoration: 'none', cursor: 'pointer', opacity: '0', // Start hidden for fade-in backgroundColor: '#333333', border: '1px solid #444444', borderRadius: '4px', right: '24px', bottom: '24px', transition: 'opacity 0.3s ease-out, background-color 0.25s ease-out, color 0.25s ease-out' }); // Responsive position const setBtnPosition = () => { if (window.innerWidth <= 1250) { btn.style.right = '16px'; btn.style.bottom = '16px'; } else { btn.style.right = '24px'; btn.style.bottom = '24px'; } }; setBtnPosition(); window.addEventListener('resize', setBtnPosition); // Append to body document.body.appendChild(btn); // Show/hide with easing const toggleButton = () => { const scrollTop = bodyContainer.scrollTop || window.scrollY; btn.style.opacity = scrollTop > 200 ? '0.8' : '0'; }; bodyContainer.addEventListener('scroll', toggleButton); window.addEventListener('scroll', toggleButton); // Scroll to top on click btn.addEventListener('click', () => { if (bodyContainer.scrollTop > 0) { bodyContainer.scrollTo({ top: 0, behavior: 'smooth' }); } else { window.scrollTo({ top: 0, behavior: 'smooth' }); } }); // Hover/focus effect btn.addEventListener('mouseenter', () => { btn.style.backgroundColor = '#fcfcfc'; btn.querySelectorAll('line, polyline').forEach(el => el.setAttribute('stroke', '#2574DB')); // lines turn #2574DB btn.style.border = '1px solid #e1e1e1'; }); btn.addEventListener('mouseleave', () => { btn.style.backgroundColor = '#333333'; btn.querySelectorAll('line, polyline').forEach(el => el.setAttribute('stroke', '#eeeeee')); // lines revert btn.style.border = '1px solid #444444'; }); })();