Skip to content

Instantly share code, notes, and snippets.

@taotiwordpress
Last active August 12, 2021 21:26
Show Gist options
  • Save taotiwordpress/94f1163a71a5fff0a34b1e11e6080fa2 to your computer and use it in GitHub Desktop.
Save taotiwordpress/94f1163a71a5fff0a34b1e11e6080fa2 to your computer and use it in GitHub Desktop.
[Back to top button]
<a href="#" id="back-to-top"></a>
jQuery(window).on('load',function(){
//Click event to scroll to top
$('#back-to-top').click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
});
jQuery(window).scroll(returnTop);
function returnTop() {
// Show button after 100px
var showAfter = 100;
if ( $(this).scrollTop() > showAfter ) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
}
#back-to-top {
position: fixed;
bottom: 8px;
right: 8px;
z-index: 9999;
cursor: pointer;
text-decoration: none;
vertical-align: middle;
display: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment