moh*_*ael 3 javascript css animation reactjs framer-motion
我是 Framer 运动的新手,我想做的是通过在旋转时移动图像来模仿轮子运动
我不知道如何使这项工作
我尝试过类似的方法但它不起作用
const imageRuning :Variants = {
hidden:{
x:"-100vw",
opacity:0
},
visible:{
x:0,
opacity:1,
transitionDuration:"3s"
},
rotation:{
rotate:[180,0],
transition:{
repeat:Infinity,
type:"tween",
ease:"linear"
}
}
}
const HomePage =()=> {
return (
<div className={style.animationContainer}>
<motion.img
className={style.animatedImage}
variants={imageRuning}
initial="hidden"
animate={["visible","rotation"]}
width={100} height={100} src="/static/me.jpg" >
</motion.img>
</div>
)
Run Code Online (Sandbox Code Playgroud)
请提供任何帮助,
看起来您正在尝试使用不同的过渡值对两个属性(x和)进行动画处理。rotate
您一次只能为一个变体制作动画,因此如果您希望它们同时发生,则需要将它们组合成一个变体。幸运的是,您可以通过在对象中列出任何动画属性来指定唯一的过渡值transition。
像这样:
visible: {
x: 0,
opacity: 1,
rotate: 180, // rotate and x animate in the same variant
transition: {
duration: 3, // default transition duration (applies to x and opacity)
rotate: {
// unique transition for rotate property only
repeat: Infinity,
type: "tween",
ease: "linear"
}
}
}
Run Code Online (Sandbox Code Playgroud)
按照您的设置方式,即使 x 动画完成 ( repeat: Infinity),对象也会继续旋转。那是你要的吗?如果您想要更多控制,可以查看动画控件。