Create a Loader with Infinite Movement using Framer Motion

Search for a command to run...

No comments yet. Be the first to comment.
You might need to ask yourself too

Let's talk about usability and 3 common mistakes you might be making when building that product. Confusing 'Account Setup' with 'Onboarding': Your onboarding flow is meant to serve a primary purpose,

Last year during Google's Built-In AI hackathon, I built an experimental Chrome extension called Clarity Lens. The product was inspired by thinking about the 'hidden 16%', the portion of the world's p

If you've used Youtube long enough, you'd realize it gradually became better in understanding your needs. I'm sure you can relate to this - you think of something, next thing, you open Youtube and it's being advertised, or you come across it on your ...

Trade-offs, accessibility concerns, and what CSS alone can’t solve

Difficulty: ⭐️ (1/5 stars)
Setup/Prerequisites: React.js, TailwindCSS, Framer Motion
Key Concepts: Using infinite animation in Framer Motion
Day 2 is a simple loader which shows infinite animation by bouncing. This animation is quite simple but shows how Framer Motion handles infinite movements which is commonly used on loaders.
Infinity movement
Easing function for a more natural movement
The ball is added first before going on to implement the infinite state and adding animations.
The animation happens in three main steps:
Wrap the ball image component with a motion.div element instead of directly applying motion to the image element to separate it’s styling.
Identify the states. There is only one state here - which is the infinite movement. The loaderVariants object is where this state is defined.
Specifying the transition type: The ininite movement and how it happens is defined in the transition property. Here, on the y-axis, I’m using the repeatType and repeat to create the infinite movement and the duration to define how fast this movement would be.
y: {
repeatType: "mirror",
repeat: Infinity,
duration: 0.5,
}
import { easeOut, motion } from "framer-motion";
import logoo from "../assets/image.png";
import grass from "../assets/grass.png";
const InfiniteLoader = () => {
return (
<div className="h-screen w-screen flex flex-col items-center justify-center afcad-flux">
<motion.div>
<img src={logoo} className="w-16 h-16" />
</motion.div>
<div>
<img src={grass} className="h-24 " />
</div>
</div>
);
};
export default InfiniteLoader;
In the loaderVariants object, the infinite state which has been previously identified is defined.
💡Remember to use gentle transitions
const loaderVariants = {
infiniteState: {
y: [50, -50],
transition: {
y: {
repeatType: "mirror",
repeat: Infinity,
duration: 0.7,
easing: easeOut,
},
},
},
};
What animation ideas do you suggest I add to this? I’m thinking of these:
Adding sound effects
Testing out other kinds of images, shapes and movement