Skip to content

Commit

Permalink
Update 08-scroll-up.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Jan 21, 2024
1 parent 329f137 commit e9e6a4b
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/js/08-scroll-up.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ goTopBtn.addEventListener('click', goTop);
window.addEventListener('scroll', trackScroll);

function trackScroll() {
const offset = window.pageYOffset;
const offset = window.scrollY;
const coords = document.documentElement.clientHeight;
if (offset > coords) {
goTopBtn.classList.add('scroll__go-top--show');
} else {
goTopBtn.classList.remove('scroll__go-top--show');
}
goTopBtn.classList.toggle('scroll__go-top--show', offset > coords);
}

function goTop() {
if (window.pageYOffset > 0) {
if (window.scrollY > 0) {
window.scrollBy(0, -75);
setTimeout(goTop, 0);
requestAnimationFrame(goTop);
}
}

0 comments on commit e9e6a4b

Please sign in to comment.