Last active
October 4, 2020 08:00
-
-
Save YakovSPb/061efb42f472849a7d5d2c74ff366591 to your computer and use it in GitHub Desktop.
arrow to up - стрелка вверх
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
// arrow to up | |
function trackScroll() { | |
var scrolled = window.pageYOffset; | |
var coords = document.documentElement.clientHeight; | |
if (scrolled > coords) { | |
goTopBtn.classList.add('back_to_top-show'); | |
} | |
if (scrolled < coords) { | |
goTopBtn.classList.remove('back_to_top-show'); | |
} | |
} | |
function backToTop() { | |
if (window.pageYOffset > 0) { | |
window.scrollBy(0, -80); | |
setTimeout(backToTop, 10); | |
} | |
} | |
var goTopBtn = document.querySelector('.up_arrow'); | |
window.addEventListener('scroll', trackScroll); | |
goTopBtn.addEventListener('click', backToTop); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment