Skip to content

Instantly share code, notes, and snippets.

@Orlandster
Last active September 27, 2018 08:58
Show Gist options
  • Save Orlandster/4e2cf44829d9a413530b42782c0cdd17 to your computer and use it in GitHub Desktop.
Save Orlandster/4e2cf44829d9a413530b42782c0cdd17 to your computer and use it in GitHub Desktop.
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');
});
}(window.jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment