Last active
January 27, 2020 09:13
-
-
Save inwardmovement/0ef3cbcbca6b291c670a224a2fccb71a to your computer and use it in GitHub Desktop.
Top button (using JS)
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
// 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