How to move plane icon with framer motion?

I have a react paper plane icon that I would like to make a cool effect by making it travel around the HTML document reaching the final position which is the menu button at the top.

This is how my react component called NavPlane looks like:

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() was supposed to cycle through 3 animations but only cycling through the first two. The 3rd is only applied when making some change to the code and updating it.

The final goal is to have a movement that goes from right corner of the page to middle, does a knot movement and then travels to the top of the page.

Any ideas how to make it cycle through as many animation variants as I want?

Source: Ask Javascript Questions

LEAVE A COMMENT