【发布时间】:2021-06-08 14:45:22
【问题描述】:
我想使用 React 每 5 秒旋转一次图像。我正在使用反应钩子。这是我的代码:
const imageRef = React.useRef(null)
React.useEffect(() => {
setInterval(() => {
imageRef.current.style.animationDuration = "2s"
imageRef.current.style.transform = "rotate(360deg)"
}, 5000)
}, [])
但是,这只是第一次旋转。我期待它在 5 秒内再次旋转。有什么想法吗?
【问题讨论】:
标签: javascript reactjs react-hooks css-animations use-ref