From 25e199ac9c2f0e03651648085799877bc8beafc4 Mon Sep 17 00:00:00 2001 From: Shariq Date: Mon, 7 Oct 2024 01:47:50 +0530 Subject: [PATCH] fix(scroll): fix scrolling behavior --- components/basic/MoveToTop.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/components/basic/MoveToTop.js b/components/basic/MoveToTop.js index 74af21ae..ee5c909a 100644 --- a/components/basic/MoveToTop.js +++ b/components/basic/MoveToTop.js @@ -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);