анимация скролла вверх

This commit is contained in:
xomimishka committed 2025-07-08 01:21:54 +03:00
1 parent 644a96101e
commit 122b63d533
1 file changed
+19 -5
+19 -5
View File
@@ -60,14 +60,28 @@ function Root() {
};
}, [hasScrolled]);
// Ускоренный плавный скролл вверх
// скролл вверх
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
const duration = 900;
const start = window.scrollY;
const startTime = performance.now();
const animateScroll = (currentTime: number) => {
const timeElapsed = currentTime - startTime;
const progress = Math.min(timeElapsed / duration, 1);
const ease = 1 - Math.pow(1 - progress, 3);
window.scrollTo(0, start * (1 - ease));
if (timeElapsed < duration) {
requestAnimationFrame(animateScroll);
}
};
requestAnimationFrame(animateScroll);
};
// Определяем, находимся ли мы на главной странице
const isHomePage = location.pathname === "/";