-
-
Notifications
You must be signed in to change notification settings - Fork 881
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8320563
commit 1f440f1
Showing
9 changed files
with
171 additions
and
11 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,60 @@ | ||
import { motionValue, AcceleratedAnimation } from "framer-motion" | ||
import * as React from "react" | ||
import { useEffect, useRef } from "react" | ||
import styled from "styled-components" | ||
|
||
const Container = styled.section` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
padding: 100px; | ||
#box { | ||
width: 100px; | ||
height: 100px; | ||
position: relative; | ||
top: 100px; | ||
left: 100px; | ||
background-color: red; | ||
opacity: 1; | ||
} | ||
` | ||
|
||
export const App = () => { | ||
const ref = useRef<HTMLDivElement>(null) | ||
|
||
useEffect(() => { | ||
if (!ref.current) return | ||
const opacity = motionValue(0) | ||
;(opacity as any).owner = { current: ref.current } | ||
const animation = new AcceleratedAnimation({ | ||
keyframes: [null, 1], | ||
motionValue: opacity, | ||
name: "opacity", | ||
}) | ||
|
||
animation.stop() | ||
|
||
// If this animation resolved, that is incorrect | ||
if (animation._resolved) { | ||
ref.current.textContent = "Error" | ||
} | ||
|
||
new AcceleratedAnimation({ | ||
keyframes: [0.4, 0.5], | ||
motionValue: opacity, | ||
name: "opacity", | ||
}) | ||
|
||
// Animation shouldn't fail if element is removed before keyframes resolve | ||
;(opacity as any).owner.current = undefined | ||
}, []) | ||
|
||
return ( | ||
<Container> | ||
<div ref={ref} id="box"> | ||
Content | ||
</div> | ||
</Container> | ||
) | ||
} |
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,42 @@ | ||
import { motion, animate } from "framer-motion" | ||
import * as React from "react" | ||
import { useEffect, useState } from "react" | ||
import styled from "styled-components" | ||
|
||
const Container = styled.section` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
padding: 100px; | ||
#box { | ||
width: 100px; | ||
height: 100px; | ||
position: relative; | ||
top: 100px; | ||
left: 100px; | ||
background-color: red; | ||
opacity: 1; | ||
} | ||
` | ||
|
||
export const App = () => { | ||
const [state, setState] = useState(false) | ||
|
||
return ( | ||
<Container> | ||
<motion.div | ||
id="box" | ||
transition={{ duration: 0 }} | ||
initial={{ transform: "scale(1)", opacity: 1 }} | ||
animate={{ | ||
transform: `scale(${state ? 1 : 2})`, | ||
opacity: state ? 1 : 0, | ||
}} | ||
onClick={() => setState(!state)} | ||
> | ||
Content | ||
</motion.div> | ||
</Container> | ||
) | ||
} |
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
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
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