Created
August 30, 2021 11:33
-
-
Save blazsmaster/c2a4c28a34dc3a53823fde290d50cb7e to your computer and use it in GitHub Desktop.
Simple scroll up script for html websites.
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
<button type="button" id="topButton" onclick="topFunction()">Top</button> | |
<style> | |
#topButton { | |
display: none; | |
position: fixed; | |
bottom: 25px; | |
right: 30px; | |
z-index: 99; | |
} | |
</style> | |
<script> | |
var mybutton = document.getElementById('topButton'); | |
window.onscroll = function() { | |
scrollFunction() | |
}; | |
function scrollFunction() { | |
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { | |
mybutton.style.display = 'block'; | |
} else { | |
mybutton.style.display = 'none'; | |
}; | |
}; | |
function topFunction() { | |
document.body.scrollTop = 0; | |
document.documentElement.scrollTop = 0; | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment