Last active
November 14, 2021 10:16
-
-
Save wireinet/17f14bfb6045a8ec7526f268128deb8f to your computer and use it in GitHub Desktop.
button to top
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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