Skip to content

Instantly share code, notes, and snippets.

@wireinet
Last active November 14, 2021 10:16
Show Gist options
  • Save wireinet/17f14bfb6045a8ec7526f268128deb8f to your computer and use it in GitHub Desktop.
Save wireinet/17f14bfb6045a8ec7526f268128deb8f to your computer and use it in GitHub Desktop.
button to top
// totop
$(document).ready(function(){
const totop = $(".totop");
// hide #back-top first
totop.hide();
// fade in #back-top
$(function () {
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
totop.fadeIn();
} else {
totop.fadeOut();
}
});
// scroll body to 0px on click
totop.click(function () {
$('body,html').animate({
scrollTop: 0
}, 800);
return false;
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment