【发布时间】:2020-07-23 18:03:13
【问题描述】:
我尝试链接两个弹簧(使用useChain),以便一个仅在另一个完成后启动,但它们同时被动画化。我做错了什么?
import React, { useRef, useState } from 'react'
import { render } from 'react-dom'
import { useSpring, animated, useChain } from 'react-spring'
function App() {
const [counter, setCounter] = useState(0)
const topRef = useRef()
const leftRef = useRef()
const { top } = useSpring({ top: (window.innerHeight * counter) / 10, ref: topRef })
const { left } = useSpring({ left: (window.innerWidth * counter) / 10, ref: leftRef })
useChain([topRef, leftRef])
return (
<div id="main" onClick={() => setCounter((counter + 1) % 10)}>
Click me!
<animated.div id="movingDiv" style={{ top, left }} />
</div>
)
}
render(<App />, document.getElementById('root'))
这是一个演示问题的代码框: https://codesandbox.io/s/react-spring-usespring-hook-m4w4t
【问题讨论】:
标签: reactjs react-spring