A back-to-top button
Show the button after the user scrolls down, and scroll smoothly when it is clicked.
jQuery · A back-to-top buttonBeginner
const $top = $('#to-top').hide();
$(window).on('scroll', function () {
$top.toggle($(this).scrollTop() > 300);
});
$top.on('click', function () {
$('html, body').animate({ scrollTop: 0 }, 400);
});scrollscrollTopanimatebutton