Build an engaging preloader animation transition using React js and Framer motion, featured on awwwards Site of the Day.

Posted by


In this tutorial, we will create a preloader animation transition using React js and Framer Motion. We will be using the Awwwards Site of the Day (SOTD) as our inspiration for the design of the preloader animation.

To get started, first make sure you have Node.js and npm installed on your machine. You can download and install Node.js from the official website at https://nodejs.org/.

Once you have Node.js and npm installed, you can create a new React project by running the following command in your terminal:

npx create-react-app preloader-animation

Next, navigate into the project directory by running the following command:

cd preloader-animation

Now install Framer Motion by running the following command:

npm install framer-motion

Now, let’s create a new file called Preloader.js in the src directory of your project. This file will contain the code for the preloader animation transition.

In the Preloader.js file, import React and the motion components from Framer Motion:

import React from 'react';
import { motion } from 'framer-motion';

Next, create a functional component called Preloader and add the following code:

const Preloader = () => {
  return (
    <motion.div
      initial={{ y: '-100vh' }}
      animate={{ y: 0 }}
      transition={{ duration: 1 }}
      style={{
        backgroundColor: '#f0f0f0',
        width: '100vw',
        height: '100vh',
        display: 'flex',
        justifyContent: 'center',
        alignItems: 'center',
        position: 'fixed',
        zIndex: 9999
      }}
    >
      <motion.svg
        width="200"
        height="200"
        viewBox="0 0 24 24"
        fill="none"
        xmlns="http://www.w3.org/2000/svg"
        animate={{ rotate: [0, 360] }}
        transition={{ repeat: Infinity, duration: 2, ease: 'linear' }}
      >
        <circle cx="12" cy="12" r="10" stroke="#4a90e2" strokeWidth="2" fill="none" />
        <path d="M16 12L12 16L8 12" stroke="#4a90e2" strokeWidth="2" strokeLinecap="round" />
      </motion.svg>
    </motion.div>
  );
};

export default Preloader;

In this code snippet, we have created a Preloader component that contains a spinning SVG animation. The preloader element will slide in from the top of the screen when it first renders and will remain in the center of the screen until the animation completes.

Next, import the Preloader component into your App.js file and render it before any other content:

import React from 'react';
import Preloader from './Preloader';

function App() {
  return (
    <div>
      <Preloader />
      {/* Your main content here */}
    </div>
  );
}

export default App;

Now when you run your React application using npm start, you should see the preloader animation transition on the screen. Feel free to customize the animation and styling to match the Awwwards Site of the Day design or to suit your own preferences.

Congratulations! You have successfully created a preloader animation transition using React js and Framer Motion. Your application now has a sleek and attractive loading animation that will impress users as they wait for content to load. Happy coding!

0 0 votes
Article Rating
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@ArcusTen
3 months ago

can you share source code link?

@Ajay-cb2tc
3 months ago

bro please update git repo.. Thanks

@abishek1808
3 months ago

Freaking awesome

@thenightwolf224
3 months ago

AMAZING ❤🔥