Site icon FSIBLOG

How to Create Multi-Page Animations Using Framer Motion

How to Create Multi-Page Animations Using Framer Motion

In the ever-evolving landscape of web and blockchain development, staying updated with the latest tools and techniques is essential. Recently, I embarked on a journey to enhance my skills in animation, routing, and blockchain technology. Here’s a breakdown of the three key areas I explored:

  1. Framer Motion: Drag Animation
  2. React Router DOM: Navigating React Applications
  3. Solidity: Understanding Global Variables

Implementing Drag Animation

Framer Motion is a powerful library for creating smooth animations in React. One of its standout features is drag animation, allowing elements to be dragged and dropped effortlessly.

Draggable Objects

The goal was to implement drag functionality with constraints. As seen in the attached image, I created draggable objects with three configurations:

Here’s the implementation:

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

const DraggableObjects = () => {
return (
<div className="container">
<h1>Draggable Objects</h1>
<div className="draggable-grid">
{/* No Constraint */}
<motion.div
className="box"
drag
>
No Constraint
</motion.div>

{/* Y-Axis Constraint */}
<motion.div
className="box"
drag="y"
>
Y-Only Constraint
</motion.div>

{/* Drag Area Constraint */}
<motion.div
className="box"
drag
dragConstraints={{ top: 0, left: 0, right: 100, bottom: 100 }}
>
Drag Constraint
</motion.div>
</div>
</div>
);
};

export default DraggableObjects;

Lessons Learned:

React Router DOM: Navigating React Applications

Efficient navigation is crucial for any React application. React Router DOM simplifies this by providing a declarative way to define routes and handle navigation.

Project Overview:

I studied React Router DOM to manage multiple pages in a React application seamlessly. The focus was on:

codeimport React from 'react';
import { BrowserRouter as Router, Route, Routes, Link } from 'react-router-dom';

const Home = () => <h2>Home Page</h2>;
const About = () => <h2>About Page</h2>;
const Profile = ({ name }) => <h2>Profile: {name}</h2>;

const App = () => {
return (
<Router>
<nav>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<Link to="/profile/John">Profile</Link>
</nav>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/profile/:name" element={<Profile />} />
</Routes>
</Router>
);
};

export default App;

Lessons Learned:

Solidity: Exploring Global Variables

Blockchain development is incomplete without understanding Solidity’s global variables. These variables provide essential information about the blockchain environment, such as transaction details, block information, and addresses.

Key Global Variables:

codepragma solidity ^0.8.0;

contract GlobalVariables {
address public sender;
uint public timestamp;
uint public value;

function setVariables() public payable {
sender = msg.sender; // Caller address
timestamp = block.timestamp; // Current block timestamp
value = msg.value; // Ether sent
}
}

Lessons Learned:

Final Thoughts

This learning journey has been incredibly rewarding, showcasing the interconnectedness of web and blockchain development. By mastering tools like Framer Motion and React Router DOM, I enhanced my ability to create dynamic and user-friendly web applications. Exploring Solidity’s global variables deepened my understanding of blockchain technology.

Whether it’s creating interactive user interfaces, seamless navigation, or robust blockchain solutions, these skills lay the foundation for building impactful projects.

Exit mobile version