mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 06:09: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]);
|
||||
|
||||
// Ускоренный плавный скролл вверх
|
||||
// скролл вверх
|
||||
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 === "/";
|
||||
|
||||
|
||||
Reference in new issue
Block a user