Last active
November 30, 2020 22:18
-
-
Save 2thecrow/9425fdf3653c299c5d15c6fac8c005b9 to your computer and use it in GitHub Desktop.
Scroll to top
This file contains hidden or 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
<a class="scroll-to-btn" id="scrollToTopBtn">наверх ↑</a> |
This file contains hidden or 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
/* scroll to top */ | |
var scrollToTopBtn = document.getElementById("scrollToTopBtn"); | |
var rootElement = document.documentElement; | |
function scrollToTop() { | |
// Scroll to top logic | |
rootElement.scrollTo({ | |
top: 0, | |
behavior: "smooth" | |
}) | |
}; | |
scrollToTopBtn.addEventListener("click", scrollToTop); |
This file contains hidden or 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
html { | |
scroll-behavior: smooth; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment