From 9f78616730bec48eddcf7eef7a2ab1ac03c1c05f Mon Sep 17 00:00:00 2001 From: pranavvraja Date: Thu, 3 Oct 2024 11:52:29 +0530 Subject: [PATCH] add: about section --- src/app/page.tsx | 4 ++ src/components/ui/text-reveal.tsx | 92 +++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/components/ui/text-reveal.tsx diff --git a/src/app/page.tsx b/src/app/page.tsx index 3d46dfb..1b432d1 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -3,11 +3,15 @@ import { useState } from "react"; import React from "react"; import HorizontalScroll from "@/components/HorizontalScrollCarousel"; +import TextReveal from "@/components/ui/text-reveal"; export default function Home() { return ( <>
+
+ +
diff --git a/src/components/ui/text-reveal.tsx b/src/components/ui/text-reveal.tsx new file mode 100644 index 0000000..782f2cf --- /dev/null +++ b/src/components/ui/text-reveal.tsx @@ -0,0 +1,92 @@ +"use client"; + +import { FC, ReactNode, useRef } from "react"; +import { motion, useScroll, useTransform, useInView } from "framer-motion"; + +import { cn } from "@/lib/utils"; + +interface TextRevealByWordProps { + text: string; + className?: string; +} + +export const TextRevealByWord: FC = ({ + text, + className, +}) => { + const targetRef = useRef(null); + + const { scrollYProgress } = useScroll({ + target: targetRef, + }); + const words = text.split(" "); + + // const ref = useRef(null); // Create a reference for the element + // const isInView = useInView(ref, { once: true }); // Trigger animation once when in view + + // Adjust the transform to make it exit only as it reaches the top of the viewport + const y = useTransform(scrollYProgress, [0, 0.25], [0, -350]); // Exit moves the heading further up (150px) + const opacity = useTransform(scrollYProgress, [0.1, 0.25], [2, 0]); // Fade out starts later and ends as it scrolls up + + return ( +
+
+ + About + + +

+ {words.map((word, i) => { + const start = i / words.length; + const end = start + 1 / words.length; + return ( + + {word} + + ); + })} +

+
+
+ ); +}; + +interface WordProps { + children: ReactNode; + progress: any; + range: [number, number]; +} + +const Word: FC = ({ children, progress, range }) => { + const opacity = useTransform(progress, range, [0, 1]); + return ( + + {children} + + {children} + + + ); +}; + +export default TextRevealByWord;