Text Scroll Animation
Text Scroll Animation é um componente de texto para React e Tailwind CSS, da biblioteca UI Layouts, com licença MIT. Copia e cola no teu projeto.
UI Layouts
MIT
text
O que é
Text Scroll Animation é um componente de texto para React e Tailwind CSS, da biblioteca UI Layouts, com licença MIT. Copia e cola no teu projeto.
Como usar
Abre o componente no catálogo, carrega em copiar, e cola no teu projeto. O prompt copiado leva o código e as regras para o teu agente o reproduzir sem alterar nada.
Cinco cópias grátis por mês. Sem cartão.
Precisa de
npm i motion @motionone/utils
Licença
Este componente vem de UI Layouts e é redistribuído sob a licença MIT, que permite uso comercial. O aviso de copyright viaja com o código.
Text Scroll Animation
'use client';
import TextAnimation from '@/components/ui/scroll-text';
import React, { useRef } from 'react';
function ScrollTextAnimation() {
return (
<div>
<div className='h-[550px] grid place-content-center'>
<h1 className='text-5xl font-semibold'>Scroll Down👇</h1>
</div>
<div className='h-[80vh] flex flex-col justify-center items-center text-center'>
<TextAnimation
text='Creative ideas start here.'
variants={{
hidden: { filter: 'blur(10px)', opacity: 0, y: 20 },
visible: {
filter: 'blur(0px)',
opacity: 1,
y: 0,
transition: { ease: 'linear' },
},
}}
classname='xl:text-8xl text-7xl max-w-md mx-auto font-medium capitalize'
/>
</div>
<div className='h-[80vh] flex items-center text-left'>
<TextAnimation
as='p'
letterAnime={true}
text="Let's team up and turn ideas into reality ✨"
classname='text-7xl max-w-md lowercase'
variants={{
hidden: { filter: 'blur(4px)', opacity: 0, y: 20 },
visible: {
filter: 'blur(0px)',
opacity: 1,
y: 0,
transition: {
duration: 0.2,
},
},
}}
/>
</div>
<div className='h-[80vh] flex justify-center items-center text-right'>
<TextAnimation
text='Turning concepts into reality'
direction='right'
classname='text-7xl max-w-md ml-auto capitalize'
/>
</div>
<div className='h-[80vh] flex justify-center items-center text-center'>
<TextAnimation
text='Dream big, work hard & achieve greatness '
direction='down'
lineAnime={true}
classname='text-7xl max-w-md mx-auto capitalize'
/>
</div>
</div>
);
}
export default ScrollTextAnimation;
// @ts-nocheck
'use client';
import { cn } from '@/lib/utils';
import { type HTMLMotionProps, motion } from 'motion/react';
import type React from 'react';
import type { JSX } from 'react';
type Direction = 'up' | 'down' | 'left' | 'right';
const containerVariants = {
hidden: {},
visible: {
transition: {
staggerChildren: 0.1,
},
},
};
const generateVariants = (direction: Direction): { hidden: any; visible: any } => {
const axis = direction === 'left' || direction === 'right' ? 'X' : 'Y';
const value = direction === 'right' || direction === 'down' ? 100 : -100;
return {
hidden: {
filter: 'blur(10px)',
opacity: 0,
[`translate${axis}`]: value,
},
visible: {
filter: 'blur(0px)',
opacity: 1,
[`translate${axis}`]: 0,
transition: {
duration: 0.4,
ease: 'easeOut',
},
},
};
};
const defaultViewport = { amount: 0.3, margin: '0px 0px 0px 0px' };
const TextAnimation = ({
as = 'h1',
text,
classname = '',
viewport = defaultViewport,
variants,
direction = 'down',
letterAnime = false,
lineAnime = false,
}: {
text: string;
classname?: string;
as?: keyof JSX.IntrinsicElements;
viewport?: {
amount?: number;
margin?: string;
once?: boolean;
};
variants?: {
hidden?: any;
visible?: any;
};
direction?: Direction;
letterAnime?: boolean;
lineAnime?: boolean;
}) => {
const baseVariants = variants || generateVariants(direction);
const modifiedVariants = {
hidden: baseVariants.hidden,
visible: {
...baseVariants.visible,
},
};
const MotionComponent = motion[as as keyof typeof motion] as React.ComponentType<
HTMLMotionProps<any>
>;
return (
<MotionComponent
whileInView='visible'
initial='hidden'
variants={containerVariants}
viewport={viewport}
className={cn(`inline-block dark:text-white text-black uppercase`, classname)}
>
{lineAnime ? (
<motion.span className={`inline-block`} variants={modifiedVariants}>
{text}
</motion.span>
) : (
<>
{text.split(' ').map((word: string, index: number) => (
<motion.span
key={`${word}-${index}`}
className={`inline-block`}
variants={letterAnime === false ? modifiedVariants : {}}
>
{letterAnime ? (
<>
{word.split('').map((letter: string, letterIndex: number) => (
<motion.span
key={letterIndex}
className={`inline-block`}
variants={modifiedVariants}
>
{letter}
</motion.span>
))}
</>
) : (
<>{word} </>
)}
</motion.span>
))}
</>
)}
</MotionComponent>
);
};
export default TextAnimation;