Skip to content

Instantly share code, notes, and snippets.

@songjiayang
Created September 3, 2014 15:09
Show Gist options
  • Save songjiayang/f6a9321fe01e33348ddd to your computer and use it in GitHub Desktop.
Save songjiayang/f6a9321fe01e33348ddd to your computer and use it in GitHub Desktop.
var scrollToTop = function() {
// Get link
var link = $('#scrollUp');
$(window).scroll(function() {
// If the user scrolled a bit (150 pixels) show the link
if ($(this).scrollTop() > 150) {
link.fadeIn(100);
} else {
link.fadeOut(100);
}
});
// On click get to top
link.click(function() {
$('html, body').animate({scrollTop: 0}, 200);
return false;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment