Created
September 3, 2014 15:09
-
-
Save songjiayang/f6a9321fe01e33348ddd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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