-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimations.ts
59 lines (53 loc) · 1.35 KB
/
animations.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import gsap from "gsap";
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
export const animatePageIn = () => {
const transitionElement = document.getElementById("transition-element");
if (transitionElement) {
const tl = gsap.timeline();
tl.set(transitionElement, {
xPercent: 0,
})
.to(transitionElement, {
xPercent: 100,
duration: 0.8,
})
.to(
transitionElement,
{
borderTopLeftRadius: "50vh",
borderBottomLeftRadius: "50vh",
duration: 0.4,
},
"<",
);
}
};
export const animatePageOut = (href: string, router: AppRouterInstance) => {
const animationWrapper = document.getElementById("transition-element");
if (animationWrapper) {
const tl = gsap.timeline();
tl.set(animationWrapper, {
xPercent: -100,
borderTopRightRadius: "50vh",
borderBottomRightRadius: "50vh",
borderTopLeftRadius: "0",
borderBottomLeftRadius: "0",
})
.to(animationWrapper, {
xPercent: 0,
duration: 0.8,
onComplete: () => {
router.push(href);
},
})
.to(
animationWrapper,
{
borderTopRightRadius: "0",
borderBottomRightRadius: "0",
duration: 0.4,
},
"<",
);
}
};