Skip to content

Commit 1d58a14

Browse files
Merge pull request #191 from Hamza1821/addedGsap
[UI Enhancement] : added Gsap animation to navbar and home page fixes #134
2 parents 7f3aa6b + 7944e24 commit 1d58a14

File tree

5 files changed

+85
-12
lines changed

5 files changed

+85
-12
lines changed

client/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@heroicons/react": "^2.1.5",
1818
"@mui/material": "^6.1.2",
1919
"client": "file:",
20+
"gsap": "^3.12.5",
2021
"mdb-react-ui-kit": "^9.0.0",
2122
"react": "^18.3.1",
2223
"react-dom": "^18.3.1",

client/src/components/Header.jsx

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
1-
import React, { useState } from "react";
1+
import React, { useState,useEffect } from "react";
22
import { Link, useNavigate } from "react-router-dom";
33
import { useAuth } from "../middleware/AuthContext";
44
import ThemeToggle from "./ThemeToggle";
5+
import gsap from 'gsap'
6+
import {tl} from './gsap.js'
57

68
const Header = () => {
79
const [isOpen, setIsOpen] = useState(false);
810
const { user, logout } = useAuth();
911
const navigate = useNavigate();
1012

13+
//gsap starts
14+
useEffect(() => {
15+
const ctx = gsap.context(() => {
16+
tl.fromTo('.navGsap',
17+
{
18+
y: -100, // Starting position (from)
19+
opacity: 0, // Starting opacity (from)
20+
},
21+
{
22+
y: 0, // Ending position (to)
23+
opacity: 1, // Ending opacity (to)
24+
duration: 0.5, // Animation duration
25+
ease: "sine.in", // Easing function
26+
stagger: 0.1,
27+
28+
}
29+
);
30+
});
31+
32+
return () => ctx.revert(); // Cleanup when the component unmounts
33+
}, []);
34+
35+
//gsap ends
36+
37+
38+
1139
const handleLogout = () => {
1240
logout();
1341
navigate("/login");
@@ -17,8 +45,8 @@ const Header = () => {
1745
<header className="bg-black text-white shadow-lg">
1846
<div className="container mx-auto flex justify-between items-center px-6 py-4">
1947
{/* Logo */}
20-
<div>
21-
<a href="/" className="text-xl font-bold text-white">
48+
<div className="navGsap">
49+
<a href="/" className=" text-xl font-bold text-white">
2250
MCA Alumni Network
2351
</a>
2452
</div>
@@ -27,25 +55,25 @@ const Header = () => {
2755
<nav className="hidden md:flex space-x-4 lg:space-x-6 text-base font-medium">
2856
<Link
2957
to="/"
30-
className="relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
58+
className="navGsap relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
3159
>
3260
Home
3361
</Link>
3462
<Link
3563
to="/about-us"
36-
className="relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
64+
className="navGsap relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
3765
>
3866
About Us
3967
</Link>
4068
<Link
4169
to="/alumni"
42-
className="relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
70+
className="navGsap relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
4371
>
4472
Our Alumni
4573
</Link>
4674
<Link
4775
to="/contact-us"
48-
className="relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
76+
className="navGsap relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
4977
>
5078
Contact Us
5179
</Link>
@@ -55,13 +83,13 @@ const Header = () => {
5583
<>
5684
<Link
5785
to="/user/dashboard"
58-
className="relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
86+
className="navGsap relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
5987
>
6088
Dashboard
6189
</Link>
6290
<button
6391
onClick={handleLogout}
64-
className="relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
92+
className="navGsap relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
6593
>
6694
Logout
6795
</button>
@@ -70,13 +98,13 @@ const Header = () => {
7098
<>
7199
<Link
72100
to="/register"
73-
className="relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
101+
className="navGsap relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
74102
>
75103
Register as Alumni
76104
</Link>
77105
<Link
78106
to="/login"
79-
className="relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
107+
className="navGsap relative text-white px-3 py-2 rounded-lg hover:text-gray-300 transition duration-300 ease-in-out hover:scale-110"
80108
>
81109
Log In
82110
</Link>

client/src/components/Home.jsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
} from "react-icons/fa"; // Import social media icons
2121
import ImageWithCursorEffect from "./ImageWithCursorEffect";
2222
import Testimonials from "./Testimonial/Testimonial";
23+
import gsap from 'gsap'
24+
2325

2426
const Home = () => {
2527
const navigate = useNavigate(); // Initialize navigate for redirection
@@ -30,6 +32,39 @@ const Home = () => {
3032
const descriptionText =
3133
"Empowering connections among MCA alumni to foster collaboration, mentorship, and professional growth within a dynamic and supportive community.";
3234

35+
useEffect(() => {
36+
const ctx = gsap.context(() => {
37+
// Ensure initial styles are set to scale 1 and opacity 1
38+
39+
40+
// Timeline for animation
41+
const tl = gsap.timeline();
42+
tl.fromTo('.homeGsap',
43+
{
44+
scale: 0, // Starting position (from)
45+
opacity: 0, // Starting opacity (from)
46+
},
47+
{
48+
scale: 1, // Ending position (to)
49+
opacity: 1, // Ending opacity (to)
50+
duration: 1, // Animation duration
51+
ease: "expo.inOut", // Easing function
52+
stagger: 0.3,
53+
54+
}
55+
);
56+
});
57+
58+
59+
60+
// Cleanup GSAP context
61+
return () => {
62+
ctx.revert();
63+
};
64+
}, []);
65+
66+
67+
3368
useEffect(() => {
3469
const interval = setInterval(() => {
3570
if (isTyping) {
@@ -81,7 +116,8 @@ const Home = () => {
81116
/>
82117

83118
{/* Left Section - Description and Buttons */}
84-
<Box sx={{ zIndex: 2, textAlign: "left", maxWidth: "45%" }}>
119+
<Box sx={{ zIndex: 2, textAlign: "left", maxWidth: "45%",transform: "scale(1)", // Adding scale
120+
opacity: 1, }} className="homeGsap ">
85121
<motion.div
86122
initial={{ opacity: 0 }}
87123
animate={{ opacity: 1 }}

client/src/components/gsap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import gsap from 'gsap'
2+
export const tl=gsap.timeline()

0 commit comments

Comments
 (0)