Skip to content

Instantly share code, notes, and snippets.

@Takaya213
Last active May 3, 2017 10:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Takaya213/5500804 to your computer and use it in GitHub Desktop.
Save Takaya213/5500804 to your computer and use it in GitHub Desktop.
Show and hide a scroll to top of page button, depending on where you are on the page.
$(window).scroll(function() {
if ($(this).scrollTop()) {
$('#toTop:hidden').stop(true, true).fadeIn();
} else {
$('#toTop').stop(true, true).fadeOut();
}
});
$(document).ready(function(){
$('#toTop').fadeOut();
$('#toTop').click(function(){
$('html, body').animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 500);
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment