-
-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix animating CSS vars with mini
animate
(#3048)
* Fixing application of CSS variables * Latest * Fix tests
- Loading branch information
1 parent
e139e74
commit 0db6ba0
Showing
4 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { animate } from "framer-motion/dom/mini" | ||
import { useEffect, useRef } from "react" | ||
|
||
export const App = () => { | ||
const ref = useRef<HTMLDivElement>(null) | ||
|
||
useEffect(() => { | ||
if (!ref.current) return | ||
|
||
try { | ||
CSS.registerProperty({ | ||
name: "--x", | ||
syntax: "<length>", | ||
inherits: false, | ||
initialValue: "0px", | ||
}) | ||
} catch (e) { | ||
// console.error(e) | ||
} | ||
|
||
const animation = animate( | ||
ref.current, | ||
{ "--x": ["0px", "500px"] }, | ||
{ duration: 0.1 } | ||
) | ||
|
||
return () => { | ||
animation.cancel() | ||
} | ||
}, []) | ||
|
||
return ( | ||
<div id="box" ref={ref} style={style}> | ||
content | ||
</div> | ||
) | ||
} | ||
|
||
const style = { | ||
width: 100, | ||
height: 100, | ||
backgroundColor: "#fff", | ||
left: "var(--x)", | ||
position: "relative", | ||
} as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters