Skip to content

Commit

Permalink
fix(scroll): fix scrolling behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Shariq2003 committed Oct 6, 2024
1 parent 48428d6 commit 25e199a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions components/basic/MoveToTop.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ const ScrollButton = () => {
};

const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
const scrollDuration = 500;
const scrollStep = -window.scrollY / (scrollDuration / 15);
const scrollInterval = setInterval(() => {
if (window.scrollY === 0) {
clearInterval(scrollInterval);
} else {
window.scrollBy(0, scrollStep);
}
}, 15);
};

window.addEventListener("scroll", toggleVisible);
Expand Down

0 comments on commit 25e199a

Please sign in to comment.