15 lines
458 B
JavaScript
15 lines
458 B
JavaScript
export function bindScrollToTop(button) {
|
|
if (!button) return;
|
|
|
|
function updateVisibility() {
|
|
button.hidden = window.scrollY <= 480;
|
|
}
|
|
|
|
window.addEventListener('scroll', updateVisibility, { passive: true });
|
|
button.addEventListener('click', () => {
|
|
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
window.scrollTo({ top: 0, behavior: reduceMotion ? 'auto' : 'smooth' });
|
|
});
|
|
updateVisibility();
|
|
}
|