-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathlayout-scaled-parent-css.tsx
More file actions
64 lines (62 loc) · 2.01 KB
/
layout-scaled-parent-css.tsx
File metadata and controls
64 lines (62 loc) · 2.01 KB
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
60
61
62
63
64
import { motion } from "framer-motion"
import { useState } from "react"
/**
* Reproduction for #3356: Layout animations misaligned in scaled parent containers.
*
* A parent motion.div has layoutRoot and CSS transform: scale(2) with
* transformOrigin: "top left". A child motion.div with layout toggles
* its CSS top position. The layout animation should smoothly interpolate
* between the two visual positions.
*
* This tests the case where scale is applied via CSS transform string
* (not motion values), which is how the original bug reporter set it up.
*/
export const App = () => {
const [toggled, setToggled] = useState(false)
return (
<div style={{ padding: 0, margin: 0 }}>
<motion.div
layoutRoot
style={{
transform: "scale(2)",
transformOrigin: "top left",
position: "absolute",
top: 0,
left: 0,
width: 200,
height: 200,
}}
>
<motion.div
id="child"
layout
style={{
position: "absolute",
top: toggled ? 50 : 0,
left: 0,
width: 50,
height: 50,
background: "red",
}}
transition={{ duration: 10, ease: () => 0.5 }}
/>
</motion.div>
<div
id="toggle"
onClick={() => setToggled((s) => !s)}
style={{
position: "absolute",
top: 500,
left: 0,
width: 100,
height: 50,
background: "blue",
cursor: "pointer",
zIndex: 10,
}}
>
Toggle
</div>
</div>
)
}