Last active
August 29, 2015 14:25
-
-
Save rochow/fc0f0c3b267e649628bf to your computer and use it in GitHub Desktop.
jQuery - Simple Back to Top Link
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 link. Automatically fades in once user has started scrolling | |
function backtotop() { | |
jQuery( window ).scroll(function() { | |
if(jQuery( this ).scrollTop() > 0) { | |
jQuery( '#toTop' ).fadeIn(); | |
} else { | |
jQuery( '#toTop' ).fadeOut(); | |
} | |
}); | |
jQuery( '#toTop' ).click(function (e) { | |
jQuery(' body,html' ).animate({ scrollTop:0 }, 800 ); | |
e.preventDefault(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment