Skip to content

Instantly share code, notes, and snippets.

@chillybin
Created November 24, 2014 03:17
Show Gist options
  • Save chillybin/fded1a432c19338e8960 to your computer and use it in GitHub Desktop.
Save chillybin/fded1a432c19338e8960 to your computer and use it in GitHub Desktop.
Back To Top jQuery
$(document).ready(function() {
var offset = 500;
var duration = 1000;
$(window).scroll(function() {
if ($(this).scrollTop() > offset) {
$('.back-to-top').fadeIn(duration);
} else {
$('.back-to-top').fadeOut(duration);
}
});
$('.back-to-top').click(function(event) {
$('html, body').animate({scrollTop: 0}, duration);
return false;
event.preventDefault();
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment