javascript - 如何使用成帧器运动移动平面图标?
问题描述
我有一个反应纸飞机图标,我想通过让它在 HTML 文档中移动到达最终位置,即顶部的菜单按钮来制作一个很酷的效果。
这就是我调用的反应组件的NavPlane
样子:
import React, { Component, useEffect } from "react";
import { useCycle } from "framer-motion";
import { FaPaperPlane } from "react-icons/fa";
import { motion } from "framer-motion";
const PlaneVariants = {
animationOne: {
x: 370,
y: 250,
transition: { ease: [0.17, 0.67, 0.83, 0.67] },
},
animationTwo: {
x: 140,
y: 150,
transition: { duration: 1.0 },
},
animationThree: {
x: 170,
y: 200,
transition: { duration: 1.0 },
},
};
export default function NavPlane() {
const [animation, cycleAnimation] = useCycle(
"animationOne",
"animationTwo",
"animationThree"
);
useEffect(() => {
setTimeout(() => {
cycleAnimation();
}, 1000);
}, []);
return (
<motion.div
className="text-2xl text-gray-600"
variants={PlaneVariants}
animate={animation}
>
<FaPaperPlane />
</motion.div>
);
}
cycleAnimation()
应该循环播放 3 个动画,但只能循环播放前两个。第三个仅在对代码进行一些更改并更新它时应用。
最终目标是进行从页面右上角到中间的运动,进行打结运动,然后移动到页面顶部。
任何想法如何让它循环通过尽可能多的动画变体?
解决方案
cycleAnimation
只前进了一步。最初它将启动“animationOne”。一旦您cycleAnimation()
在 1 秒后调用,“animationTwo”将启动。如果你想玩“animationThree”,你需要另一个计时器
useEffect(() => {
setTimeout(cycleAnimation, 1000); // start "animationTwo" after 1 second
setTimeout(cycleAnimation, 2000); // start "animationThree" after 2 seconds
}, []);
推荐阅读
- angular - 在Angular 2+中嵌入模态的对话框前面显示mat-select
- tensorflow - 运行 object_detection_tutorial TypeError 的问题:load() 缺少 2 个必需的位置参数
- linux - 工作时sqlmap语法不问任何问题
- python - 查找不包含任何字符 ( . - \ / ) 的列表元素
- reactjs - docz 构建失败 - 无法解析“文件路径”中的“dom-helpers/util/requestAnimationFrame”
- java - Android Studio:如何将变量从一个 java 文件保存到另一个
- mongodb - 如何在 MongoDB 分片集群中处理不同的服务器类型
- c# - 尝试使用 PNG C# 发布多表单
- python - 如何在 Python 中以小时、分钟和秒显示“X”轴刻度?
- ios - 复杂布局的动态 CollectionViewHeader 单元格大小