font: tweak duration of some animations
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import gsap from "gsap";
|
import gsap from "gsap";
|
||||||
|
|
||||||
const SELECTOR_SPEED = 500;
|
const DURATION = 0.11;
|
||||||
|
|
||||||
export const useButtonNavigation = <T extends Record<string, Rect>>({
|
export const useButtonNavigation = <T extends Record<string, Rect>>({
|
||||||
buttons,
|
buttons,
|
||||||
@@ -143,18 +143,6 @@ export const useButtonNavigation = <T extends Record<string, Rect>>({
|
|||||||
|
|
||||||
const graph = buildNavigationGraph(navigation);
|
const graph = buildNavigationGraph(navigation);
|
||||||
|
|
||||||
const calculateDistance = (
|
|
||||||
[x1, y1, w1, h1]: Rect,
|
|
||||||
[x2, y2, w2, h2]: Rect,
|
|
||||||
): number => {
|
|
||||||
const cx1 = x1 + w1 / 2;
|
|
||||||
const cy1 = y1 + h1 / 2;
|
|
||||||
const cx2 = x2 + w2 / 2;
|
|
||||||
const cy2 = y2 + h2 / 2;
|
|
||||||
|
|
||||||
return Math.sqrt((cx2 - cx1) ** 2 + (cy2 - cy1) ** 2);
|
|
||||||
};
|
|
||||||
|
|
||||||
const animateToButton = (targetButton: Entry, path?: Array<Entry> | null) => {
|
const animateToButton = (targetButton: Entry, path?: Array<Entry> | null) => {
|
||||||
const pathButtons = path && path.length > 0 ? path : [targetButton];
|
const pathButtons = path && path.length > 0 ? path : [targetButton];
|
||||||
|
|
||||||
@@ -164,14 +152,11 @@ export const useButtonNavigation = <T extends Record<string, Rect>>({
|
|||||||
isAnimating.value = false;
|
isAnimating.value = false;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
let prevRect = selectorPosition.value;
|
|
||||||
|
|
||||||
selectorPosition.value = [...selectorPosition.value];
|
selectorPosition.value = [...selectorPosition.value];
|
||||||
|
|
||||||
for (const button of pathButtons) {
|
for (const button of pathButtons) {
|
||||||
const buttonRect = buttons[button]!;
|
const buttonRect = buttons[button]!;
|
||||||
const distance = calculateDistance(prevRect, buttonRect);
|
|
||||||
const duration = distance / SELECTOR_SPEED;
|
|
||||||
|
|
||||||
timeline.to(
|
timeline.to(
|
||||||
selectorPosition.value,
|
selectorPosition.value,
|
||||||
@@ -180,13 +165,11 @@ export const useButtonNavigation = <T extends Record<string, Rect>>({
|
|||||||
[1]: buttonRect[1],
|
[1]: buttonRect[1],
|
||||||
[2]: buttonRect[2],
|
[2]: buttonRect[2],
|
||||||
[3]: buttonRect[3],
|
[3]: buttonRect[3],
|
||||||
duration,
|
duration: DURATION,
|
||||||
ease: "none",
|
ease: "none",
|
||||||
},
|
},
|
||||||
"+=0",
|
"+=0",
|
||||||
);
|
);
|
||||||
|
|
||||||
prevRect = buttonRect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedButton.value = targetButton;
|
selectedButton.value = targetButton;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import gsap from "gsap";
|
import gsap from "gsap";
|
||||||
|
|
||||||
|
const DURATION = 0.11;
|
||||||
|
|
||||||
export const useMenuAnimation = (key: string, isOpen: Ref<boolean>) => {
|
export const useMenuAnimation = (key: string, isOpen: Ref<boolean>) => {
|
||||||
const animation = useState(`animation-${key}`, () => ({
|
const animation = useState(`animation-${key}`, () => ({
|
||||||
playing: false,
|
playing: false,
|
||||||
@@ -8,7 +10,6 @@ export const useMenuAnimation = (key: string, isOpen: Ref<boolean>) => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
watch(isOpen, (current, previous) => {
|
watch(isOpen, (current, previous) => {
|
||||||
const duration = 0.1;
|
|
||||||
const timeline = gsap.timeline({
|
const timeline = gsap.timeline({
|
||||||
onStart: () => {
|
onStart: () => {
|
||||||
animation.value.playing = true;
|
animation.value.playing = true;
|
||||||
@@ -23,24 +24,24 @@ export const useMenuAnimation = (key: string, isOpen: Ref<boolean>) => {
|
|||||||
.fromTo(
|
.fromTo(
|
||||||
animation.value,
|
animation.value,
|
||||||
{ stage1Offset: 48 },
|
{ stage1Offset: 48 },
|
||||||
{ stage1Offset: 0, duration },
|
{ stage1Offset: 0, ease: "none", duration: DURATION },
|
||||||
)
|
)
|
||||||
.fromTo(
|
.fromTo(
|
||||||
animation.value,
|
animation.value,
|
||||||
{ stage2Offset: 48 },
|
{ stage2Offset: 48 },
|
||||||
{ stage2Offset: 0, duration },
|
{ stage2Offset: 0, ease: "none", duration: DURATION },
|
||||||
);
|
);
|
||||||
} else if (current === false && previous === true) {
|
} else if (current === false && previous === true) {
|
||||||
timeline
|
timeline
|
||||||
.fromTo(
|
.fromTo(
|
||||||
animation.value,
|
animation.value,
|
||||||
{ stage2Offset: 0 },
|
{ stage2Offset: 0 },
|
||||||
{ stage2Offset: 48, duration },
|
{ stage2Offset: 48, ease: "none", duration: DURATION },
|
||||||
)
|
)
|
||||||
.fromTo(
|
.fromTo(
|
||||||
animation.value,
|
animation.value,
|
||||||
{ stage1Offset: 0 },
|
{ stage1Offset: 0 },
|
||||||
{ stage1Offset: 48, duration },
|
{ stage1Offset: 48, ease: "none", duration: DURATION },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user