Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

207 changes: 105 additions & 102 deletions src/Pages/Home_Page/Event_Section/Event.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import React, { useEffect, useRef } from "react";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useNavigate } from "react-router-dom";

import HacknocturneImg from "../../../assets/Hacknocturne.jpeg";
import csocImg from "../../../assets/csoc.jpeg";
import techvistaraImg from "../../../assets/Techvistara.jpg";
import codecafeImg from "../../../assets/CodeCafe.jpg";
gsap.registerPlugin(ScrollTrigger);

export const Event = () => {
Expand All @@ -15,7 +18,7 @@ export const Event = () => {
slug: "hacknocturne",
name: "HackNocturne",
number: 0,
image: "https://images.unsplash.com/photo-1540575467063-178a50c2df87?w=800&q=80",
image: HacknocturneImg,
description:
"HackNocturne is CodeShack's flagship annual inter-college hackathon where students participate in a 24-hour non-stop coding challenge.",
buttonText: "VIEW DETAILS"
Expand All @@ -25,7 +28,7 @@ export const Event = () => {
slug: "tech-vistara",
name: "Tech Vistara",
number: 1,
image: "https://images.unsplash.com/photo-1509062522246-3755977927d7?w=800&q=80",
image: techvistaraImg,
description:
"Orientation program designed to introduce freshers to tech culture.",
buttonText: "LEARN MORE"
Expand All @@ -35,7 +38,7 @@ export const Event = () => {
slug: "codecafe",
name: "CodeCafe",
number: 2,
image: "https://images.unsplash.com/photo-1531482615713-2afd69097998?w=800&q=80",
image: codecafeImg,
description:
"Webinar and talk series on technology, placements, and careers.",
buttonText: "EXPLORE"
Expand All @@ -45,114 +48,114 @@ export const Event = () => {
slug: "csoc",
name: "CSoC (CodeShack Summer of Code)",
number: 3,
image: "https://images.unsplash.com/photo-1522071820081-009f0129c71c?w=800&q=80",
image: csocImg,
description:
"A structured summer learning program focused on real-world skills.",
buttonText: "JOIN NOW"
}
];

useEffect(() => {
cardsRef.current.forEach((card, index) => {
if (!card) return;

const numberEl = card.querySelector(".event-number");
const glowEl = card.querySelector(".event-glow");

const valueObj = { value: 0 };
const targetValue = events[index].number;

/* Timeline (paused by default) */
const tl = gsap.timeline({ paused: true });

/* Card animation */
tl.fromTo(
card,
{ opacity: 0, y: 80 },
{
opacity: 1,
y: 0,
duration: 1,
ease: "power3.out"
},
0
);

/* Glow animation */
tl.fromTo(
glowEl,
{ opacity: 0, scale: 0.6 },
{
opacity: 0.8,
scale: 1.2,
duration: 0.6,
ease: "power2.out"
},
0.1
);

tl.to(
glowEl,
{
opacity: 0.25,
scale: 1,
duration: 0.6,
ease: "power2.out"
},
0.8
);

/* Number animation */
tl.to(
valueObj,
{
value: targetValue,
duration: 1.2,
ease: "power2.out",
snap: { value: 1 },
onUpdate: () => {
numberEl.textContent = String(valueObj.value).padStart(2, "0");
cardsRef.current.forEach((card, index) => {
if (!card) return;

const numberEl = card.querySelector(".event-number");
const glowEl = card.querySelector(".event-glow");

const valueObj = { value: 0 };
const targetValue = events[index].number;

/* Timeline (paused by default) */
const tl = gsap.timeline({ paused: true });

/* Card animation */
tl.fromTo(
card,
{ opacity: 0, y: 80 },
{
opacity: 1,
y: 0,
duration: 1,
ease: "power3.out"
},
0
);

/* Glow animation */
tl.fromTo(
glowEl,
{ opacity: 0, scale: 0.6 },
{
opacity: 0.8,
scale: 1.2,
duration: 0.6,
ease: "power2.out"
},
0.1
);

tl.to(
glowEl,
{
opacity: 0.25,
scale: 1,
duration: 0.6,
ease: "power2.out"
},
0.8
);

/* Number animation */
tl.to(
valueObj,
{
value: targetValue,
duration: 1.2,
ease: "power2.out",
snap: { value: 1 },
onUpdate: () => {
numberEl.textContent = String(valueObj.value).padStart(2, "0");
}
},
0
);

/* ScrollTrigger */
ScrollTrigger.create({
trigger: card,
start: "top 80%",

onEnter: () => {
tl.restart();
},

onLeaveBack: () => {
// Fade out smoothly when scrolling up
gsap.to(card, {
opacity: 0,
y: 80,
duration: 0.5,
ease: "power2.in",
onComplete: () => {
// Reset everything AFTER fade-out
tl.pause(0);

valueObj.value = 0;
numberEl.textContent = "00";

gsap.set(glowEl, {
opacity: 0,
scale: 0.6
});
}
});
}
},
0
);

/* ScrollTrigger */
ScrollTrigger.create({
trigger: card,
start: "top 80%",

onEnter: () => {
tl.restart();
},

onLeaveBack: () => {
// Fade out smoothly when scrolling up
gsap.to(card, {
opacity: 0,
y: 80,
duration: 0.5,
ease: "power2.in",
onComplete: () => {
// Reset everything AFTER fade-out
tl.pause(0);

valueObj.value = 0;
numberEl.textContent = "00";

gsap.set(glowEl, {
opacity: 0,
scale: 0.6
});
}
});
}
});
});

});
});

return () => ScrollTrigger.getAll().forEach(t => t.kill());
}, []);
return () => ScrollTrigger.getAll().forEach(t => t.kill());
}, []);



Expand Down
Loading