mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 05:59:45 +00:00
анимация скролла вверх
This commit is contained in:
1 parent
644a96101e
commit
122b63d533
1 file changed
+19
-5
+19
-5
@@ -60,14 +60,28 @@ function Root() {
|
|||||||
};
|
};
|
||||||
}, [hasScrolled]);
|
}, [hasScrolled]);
|
||||||
|
|
||||||
// Ускоренный плавный скролл вверх
|
// скролл вверх
|
||||||
const scrollToTop = () => {
|
const scrollToTop = () => {
|
||||||
window.scrollTo({
|
const duration = 900;
|
||||||
top: 0,
|
const start = window.scrollY;
|
||||||
behavior: "smooth",
|
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 === "/";
|
const isHomePage = location.pathname === "/";
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user