Skip to content

Instantly share code, notes, and snippets.

@inwardmovement
Last active January 27, 2020 09:13
Show Gist options
  • Save inwardmovement/0ef3cbcbca6b291c670a224a2fccb71a to your computer and use it in GitHub Desktop.
Save inwardmovement/0ef3cbcbca6b291c670a224a2fccb71a to your computer and use it in GitHub Desktop.
Top button (using JS)
// TOP BUTTON
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 0 || document.documentElement.scrollTop > 0) {
document.getElementById("top-btn").style.display = "block";
} else {
document.getElementById("top-btn").style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment