Skip to content

Instantly share code, notes, and snippets.

@Ginnw2
Created November 26, 2021 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ginnw2/b24caf8e872ffdb49a78081c75e95b1c to your computer and use it in GitHub Desktop.
Save Ginnw2/b24caf8e872ffdb49a78081c75e95b1c to your computer and use it in GitHub Desktop.
#html
<a class="toTop hidden" href="#top"><i class="fas fa-chevron-up"></i></a>
#style
.toTop{
position: fixed;
right: 50px;
bottom: 20px;
}
.toTop.hidden{
display: none;
}
#script
$(document).scroll(function(){
var y = $(this).scrollTop();
if (y > 800) {
$('.toTop').removeClass('hidden');
} else {
$('.toTop').addClass('hidden');
}
});
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment