Text Animatinon
A timeline animation using Framer Motion that animates items one by one as you reach each specific section
A timeline animation using Framer Motion that animates items one by one as you reach each specific section
npm install motion @motionone/utils
1import { type HTMLMotionProps, motion, useInView } from "motion/react"2import type React from "react"3import type { Variants } from "motion/react"45type TimelineContentProps<T extends keyof HTMLElementTagNameMap> = {6children: React.ReactNode7animationNum: number8className?: string9timelineRef: React.RefObject<HTMLElement | null>10as?: T11customVariants?: Variants12once?: boolean13} & HTMLMotionProps<T>1415export const TimelineContent = <T extends keyof HTMLElementTagNameMap = "div">({16children,17animationNum,18timelineRef,19className,20as,21customVariants,22once=false,23...props24}: TimelineContentProps<T>) => {25const defaultSequenceVariants = {26visible: (i: number) => ({27filter: "blur(0px)",28y: 0,29opacity: 1,30transition: {31delay: i * 0.5,32duration: 0.5,33},34}),35hidden: {36filter: "blur(20px)",37y: 0,38opacity: 0,39},40}4142// Use custom variants if provided, otherwise use default43const sequenceVariants = customVariants || defaultSequenceVariants4445const isInView = useInView(timelineRef, {46once47})4849const MotionComponent = motion[as || "div"] as React.ElementType5051return (52<MotionComponent53initial="hidden"54animate={isInView ? "visible" : "hidden"}55custom={animationNum}56variants={sequenceVariants}57className={className}58{...props}59>60{children}61</MotionComponent>62)63}
Prop | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | The content to be displayed within the timeline. | |
as | keyof HTMLElementTagNameMap | div | The HTML element to use for the timeline. |
timelineRef | React.RefObject<HTMLDivElement> | A reference to the timeline element for manipulation. | |
once | boolean | false | Whether to animate only once. |
variants | Variants | A set of variants to animate the timeline. |