Created
May 29, 2019 15:59
-
-
Save ennjoy/4202bdb4b9c5c6385f0c6ef4c7eb47d4 to your computer and use it in GitHub Desktop.
up button
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 id="up-btn">Наверх</button> | |
<script> | |
var btnUp = document.getElementById('up-btn'); | |
window.onscroll = function() { | |
var offset = window.pageYOffset; | |
if(offset > window.innerHeight) { | |
btnUp.style.display = 'inline'; | |
} | |
else { | |
btnUp.style.display = 'none'; | |
} | |
} | |
btnUp.onclick = function() { | |
jQuery('html').animate({scrollTop:0},100); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment