Framer Motion – 如何在没有初始部分的情况下重复动画?

huangapple go评论87阅读模式
英文:

Framer Motion - How do I repeat an animation without the initial part?

问题

我想使用Framer Motion在我的React项目中以非常特定的方式对一个元素进行动画。当动画首次开始时,它应该从页面底部向上移动,但一旦它到达大约中间位置,它应该只是无限地漂浮在原地,永远不返回到初始位置。

我对Framer Motion相对新手,找不到解决方案。我也尝试过关键帧,但在某个时候动画必须结束并从头开始重复。我该怎么做才能创建这种行为?谢谢。

英文:

I'd like to animate an element in a very specific way using Framer Motion on my React project. It should go up from the bottom of the page when the animation first starts, but, once it hits about middle, it should just keep floating in place indefinitely - without ever going back to its initial position.

I'm fairly new to Framer Motion and couldn't find a solution. I've tried keyframes as well, but at some point the animation has to end and repeat from the beginning. What can I do to create this kind of behavior? Thank you.

答案1

得分: 1

你可以通过第一动画的持续时间来延迟第二个动画。这样,第二个动画将在第一个部分结束后无缝启动,考虑到没有任何事件参与。例如,如果第一个动画的持续时间为5秒,将第二个动画延迟5秒。

至于使用framer-motion来实现这一点,你可以使用motion以及第一个动画的initialanimate属性,以及第二个动画的useAnimate钩子。你可以在framer-motion文档中找到所有实现步骤。

希望这对你有帮助,祝你好运!

英文:

You could delay the second animation by the duration of the first animation. That way the second animation will seamlessly fire up as soon as the first bit ends considering there aren't any events involved. For example, if the duration of the first animation is 5 seconds, delay the second animation by 5 seconds.

As for implementing this using framer-motion, you can use the motion and the initial and animate props for the first animation and the useAnimate hook for the second animation. You can find all the steps for implementation in the framer-motion docs.

Hope this helps and good luck!

huangapple
  • 本文由 发表于 2023年7月11日 11:41:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76658583.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定