admin管理员组文章数量:1277391
I am using Framer Motion in React to animate a circular progress bar. I have managed to get the actual circle to animate based on a a dynamic duration (that gets passed from a parent ponent). The issue is that I need to the opacity to immediately be set to 1, while the rest of the animation would be based on the duration of the prop being passed down.
Something like this in css: transition: opacity 0s, {motionproperty} {duration}
where the last two are the motion property pathLength and the dynamic duration.
Currently this is what my ProgressCircle ponent and the Framer Motion animate variants look as follows:
const MotionProgressCircle = styled(motion.circle)``;
const progressCircleVariants = {
initial: {
pathLength: 0,
strokeWidth: 3,
opacity: 0,
r: initRadius,
transition: {
duration: '500',
strokeDashoffset: 0
}
},
hover: {
strokeWidth: 5,
r: hoverRadius
},
playing: (duration) => ({
pathLength: 1,
transition: {
type: "tween",
duration: duration
},
opacity: 1,
})
};
const ProgressCircle = ({ duration }) => {
return (
<div>
<StyledContainer >
<MotionProgressCircle
variants={progressCircleVariants}
initial="initial"
animate="playing"
custom={duration}
whileHover="hover"
fill="transparent"
stroke="currentColor"
cx="1em"
cy="1em"
strokeLinecap="round"
/>
</StyledContainer>
</div>
);
};
I have tried just interpolating the different values of the transition property, but this did not work.
I am using Framer Motion in React to animate a circular progress bar. I have managed to get the actual circle to animate based on a a dynamic duration (that gets passed from a parent ponent). The issue is that I need to the opacity to immediately be set to 1, while the rest of the animation would be based on the duration of the prop being passed down.
Something like this in css: transition: opacity 0s, {motionproperty} {duration}
where the last two are the motion property pathLength and the dynamic duration.
Currently this is what my ProgressCircle ponent and the Framer Motion animate variants look as follows:
const MotionProgressCircle = styled(motion.circle)``;
const progressCircleVariants = {
initial: {
pathLength: 0,
strokeWidth: 3,
opacity: 0,
r: initRadius,
transition: {
duration: '500',
strokeDashoffset: 0
}
},
hover: {
strokeWidth: 5,
r: hoverRadius
},
playing: (duration) => ({
pathLength: 1,
transition: {
type: "tween",
duration: duration
},
opacity: 1,
})
};
const ProgressCircle = ({ duration }) => {
return (
<div>
<StyledContainer >
<MotionProgressCircle
variants={progressCircleVariants}
initial="initial"
animate="playing"
custom={duration}
whileHover="hover"
fill="transparent"
stroke="currentColor"
cx="1em"
cy="1em"
strokeLinecap="round"
/>
</StyledContainer>
</div>
);
};
I have tried just interpolating the different values of the transition property, but this did not work.
Share Improve this question asked Mar 16, 2022 at 18:59 amoamo 611 gold badge1 silver badge4 bronze badges1 Answer
Reset to default 9You can list the transition setting for individual properties by adding them to the transition
object:
playing: (duration) => ({
pathLength: 1,
opacity: 1,
transition: {
type: "tween",
duration: duration, // default duration for this transition
opacity: {
duration: 0 // custom duration for opacity property only
}
},
})
本文标签: javascriptFramer Motionuse different durations on transition propertiesStack Overflow
版权声明:本文标题:javascript - Framer Motion - use different durations on transition properties - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741201122a2357243.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论