Skip to content

Instantly share code, notes, and snippets.

@raphaelchaib
Created March 21, 2013 18:40
Show Gist options
  • Save raphaelchaib/5215547 to your computer and use it in GitHub Desktop.
Save raphaelchaib/5215547 to your computer and use it in GitHub Desktop.
Javascript: Scroll window to top. For this snippet work the container of icon (or text) must be "display: none" for fade-in and fade-out.
// Scroll to top
jQuery(window).scroll(function() {
if( jQuery(this).scrollTop() != 0 ) {
jQuery('.scroll-to-top').fadeIn();
} else {
jQuery('.scroll-to-top').fadeOut();
}
});
jQuery('.scroll-to-top').click(function() {
jQuery('html, body').animate({
scrollTop : 0
}, 600);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment