Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
jQuery: scroll to top
(function ($) {
// display button after 60px scrolled
const showAtOffset = 60;
const $backToTop = $('.scroll-top-wrapper');
// Show and hide the Button
$(document).on( 'scroll', function(){
($(window).scrollTop() > showAtOffset) ? $backToTop.addClass('show'): $backToTop.removeClass('show');
// Scroll top Top
$backToTop.on('click', function() {
$('html, body').animate({scrollTop: 0}, 500, 'linear');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment