Replies: 1 comment
-
|
The import { useEffect } from 'react'
import { useSpring, animated } from '@react-spring/web'
function PulsingBox() {
const [springs, api] = useSpring(() => ({
scale: 1,
config: { tension: 300, friction: 10 },
}))
useEffect(() => {
const runAnimation = () => {
api.start({
to: async (next) => {
await next({ scale: 1.2 })
await next({ scale: 1 })
},
})
}
runAnimation() // run immediately
const id = setInterval(runAnimation, 10_000)
return () => clearInterval(id)
}, [api])
return <animated.div style={{ transform: springs.scale.to(s => `scale(${s})`) }} />
}The If you want a simpler in-out pulse without sequencing: useEffect(() => {
const id = setInterval(() => {
api.start({ scale: 1.2, onRest: () => api.start({ scale: 1 }) })
}, 10_000)
return () => clearInterval(id)
}, [api])
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to run an animation every 10 seconds. The code below doesn't work at all. I had a state where the animations would run when first mounting the component. However, when I navigated to a different page and then back to the one with the animated div, it wasn't started either.
Beta Was this translation helpful? Give feedback.
All reactions