Last active
September 27, 2018 08:58
-
-
Save Orlandster/4e2cf44829d9a413530b42782c0cdd17 to your computer and use it in GitHub Desktop.
jQuery: scroll to top
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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