Skip to content

Instantly share code, notes, and snippets.

@huy-tran
Created March 24, 2016 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huy-tran/540ad8286d9eb04e419d to your computer and use it in GitHub Desktop.
Save huy-tran/540ad8286d9eb04e419d to your computer and use it in GitHub Desktop.
Back To Top Button
// Back To Top button
var offset = 500;
var offsetOpacity = 1500;
var scrollDuration = 700;
var $backToTop = $('.gh-top');
$(window).scroll(function () {
if ($(this).scrollTop() > offset) {
$backToTop.addClass('gh-top-visible');
} else {
$backToTop.removeClass('gh-top-visible');
}
});
$backToTop.click(function (e) {
e.preventDefault();
$('body, html').animate({
scrollTop: 0,
}, scrollDuration);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment