component BackToTop { props { label = "Back to top" assistiveLabel = "Return to the top of the page" threshold = 500 } state visible = false functions { function updateBackToTopVisibility() { visible = window.scrollY > threshold } function scrollToTop() { window.scrollTo({ top: 0, behavior: "smooth" }) } } lifecycle { mount { updateBackToTopVisibility() window.addEventListener( "scroll", updateBackToTopVisibility, { passive: true } ) } unmount { window.removeEventListener( "scroll", updateBackToTopVisibility ) } } watch visible { console.debug( "Back-to-top visibility:", value, previous ) } view {
} }