Created
March 24, 2016 04:49
-
-
Save huy-tran/540ad8286d9eb04e419d to your computer and use it in GitHub Desktop.
Back To Top Button
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
// 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