Show a button after scrolling down and scroll smoothly back to the top when it is clicked.
HTML
<button class="lotgrafix-back-to-top" aria-label="Back to top" hidden>↑</button>
.lotgrafix-back-to-top {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 999;
}
main.js
var btn = document.querySelector( '.lotgrafix-back-to-top' );
if ( btn ) {
window.addEventListener( 'scroll', function () {
btn.hidden = window.scrollY < 400;
}, { passive: true } );
btn.addEventListener( 'click', function () {
window.scrollTo( { top: 0, behavior: 'smooth' } );
} );
}