Skip to content

Instantly share code, notes, and snippets.

@unwiredtech
Last active June 8, 2023 01:38
Show Gist options
  • Save unwiredtech/b2dbb12ed1d1e089f0d61f641702632e to your computer and use it in GitHub Desktop.
Save unwiredtech/b2dbb12ed1d1e089f0d61f641702632e to your computer and use it in GitHub Desktop.
Scroll to Top with auto hide
// hide the topbutton on page load/ready.
jQuery('.scrolltop-btn').hide();
//Check to see if the window is top if not then display button
jQuery(window).scroll(function(){
if (jQuery(this).scrollTop() > 100) {
jQuery('.scrolltop-btn').show().fadeIn();
} else {
jQuery('.scrolltop-btn').fadeOut().hide();
}
});
//Click event to scroll to top
jQuery('.scrolltop-btn').click(function(){
jQuery('html, body').animate({scrollTop : 0},360);
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment