[英]How to re-run a squence of animation in reactjs and framer-motion
i have a sequence of animations that i want to run for unlimited times, i tried this, it'works only for the first time, and the animation is not executed again我有一系列动画,我想无限次运行,我试过了,它只在第一次运行,animation 没有再次执行
async function sequence() { await animation.start({ x: line_1.current?.getBoundingClientRect()?.width, }); await animation.start({ y: -Number(_line.current?.getBoundingClientRect().height) / 2, }); await animation.start({ x: Number(line_2.current?.getBoundingClientRect()?.width) * 2, }); animation.start({ transition: { repeatDelay: 1, repeat: Infinity, repeatType: "loop", }, }); } useEffect(() => { sequence(); }, []); return <motion.div className="w-3 h-3 bg-red-600" animate={animation} />
what I want is to run every time from the start, thanks in advance我想要的是每次从头开始运行,在此先感谢
transition
should be placed at the main element rather than inside the sequence
, since the transition attributes would be applied to every animation calls. transition
应该放在 main 元素而不是在sequence
内部,因为 transition 属性将应用于每个 animation 调用。
async function sequence() {
await animation.start({
x: line_1.current?.getBoundingClientRect()?.width,
});
await animation.start({
y: -Number(_line.current?.getBoundingClientRect().height) / 2,
});
animation.start({
x: Number(line_2.current?.getBoundingClientRect()?.width) * 2,
});
}
useEffect(() => {
sequence();
}, []);
return <motion.div
className="w-3 h-3 bg-red-600"
animate={animation}
transition={{
repeatDelay: 1,
repeat: Infinity,
repeatType: "loop",
}}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.