Animate Path
#1370
-
I've been using react-spring's I'd like to animate a SVG const P0 = { x: 20, y: 50 }
const P1 = { x: 20, y: 75 }
const P2 = { x: 110, y: 20 }
const P3 = { x: 180, y: 50 }
const Bezier = () => {
const [ref, inView] = useInView( { threshold: 1, } )
const props = useSpring( { number: inView ? P0.x : P3.x } )
...
return <div ref={ref} style={ { height: `200pt`, } }>
<animated.span>
<svg
width="100%"
height="100%"
viewBox={`0 0 ${ width } ${ height }`}
preserveAspectRatio="XMaxYMax"
>
...
<animated.path
stroke={`var(--color-text)`}
strokeWidth={`1.5px`}
fill={`none`}
d={`M ${P0.x} ${P0.y} C ${P1.x} ${P1.y}, ${P2.x} ${P2.y}, ${P3.x} ${P3.y}`} // <- Can I interpolate this?
/> |
Beta Was this translation helpful? Give feedback.
Answered by
tnorlund
Apr 7, 2021
Replies: 1 comment
-
I fixed this by interpolating between different 'output's: <animated.path
stroke={`var(--color-text)`}
strokeWidth={`1.5px`}
fill={`none`}
d={ props.x.interpolate( {
range: [ min_x, max_x ], output: [ d0, d1 ]
} ) }
/> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
tnorlund
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I fixed this by interpolating between different 'output's: