MCPcopy Index your code
hub / github.com/adobe/react-spectrum / startAnimation

Function startAnimation

packages/dev/docs/pages/blog/SubmenuAnimation.tsx:36–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34
35 useEffect(() => {
36 let startAnimation = () => {
37 let cancel = animate([
38 {
39 time: 500,
40 perform() {
41 setTimeout(() => {
42 setHovered('Option 1');
43 }, 500);
44 }
45 },
46 {
47 time: 700,
48 perform() {
49 let option1Rect = option1Ref.current!.getBoundingClientRect();
50 let option2Rect = option2Ref.current!.getBoundingClientRect();
51 let x =
52 option1Rect.left + option1Rect.width / 2 - ref.current!.getBoundingClientRect().left;
53 let y =
54 option1Rect.top + option1Rect.height / 2 - ref.current!.getBoundingClientRect().top;
55 let y_target =
56 option2Rect.top + option2Rect.height / 2 - ref.current!.getBoundingClientRect().top;
57 mouseRef.current!.animate(
58 {
59 transform: [`translate(${x}px, ${y}px)`, `translate(${x}px, ${y_target}px)`]
60 },
61 {duration: 1000, fill: 'forwards', easing: 'ease-in-out'}
62 );
63 setTimeout(() => {
64 setHovered('Option 2');
65 setIsSubmenuOpen(true);
66 }, 350);
67 }
68 },
69 {
70 time: 700,
71 perform() {}
72 },
73 {
74 time: 700,
75 perform() {
76 let option1Rect = option1Ref.current!.getBoundingClientRect();
77 let option2Rect = option2Ref.current!.getBoundingClientRect();
78 let submenuOptionRect = submenuOptionRef.current!.getBoundingClientRect();
79 let x =
80 option1Rect.left + option1Rect.width / 2 - ref.current!.getBoundingClientRect().left;
81 let y =
82 option2Rect.top + option2Rect.height / 2 - ref.current!.getBoundingClientRect().top;
83 let x_target =
84 submenuOptionRect.left +
85 submenuOptionRect.width / 2 -
86 ref.current!.getBoundingClientRect().left;
87 let y_target =
88 submenuOptionRect.top +
89 submenuOptionRect.height / 2 -
90 ref.current!.getBoundingClientRect().top;
91 mouseRef.current!.animate(
92 {
93 transform: [`translate(${x}px, ${y}px)`, `translate(${x_target}px, ${y_target}px)`]

Callers 1

SubmenuAnimationFunction · 0.70

Calls 3

animateFunction · 0.90
cancelFunction · 0.85
cancelMethod · 0.80

Tested by

no test coverage detected