Created
March 21, 2013 18:40
-
-
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.
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
// 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