Image and text animation

diwali
This commit is contained in:
2024-09-27 01:00:12 +05:30
parent 8d0a8903b4
commit 127e024374
19 changed files with 536 additions and 42 deletions

View File

@ -0,0 +1,36 @@
// src/components/AnimatedText.tsx
import { ReactNode, useRef } from 'react';
import useInView from '@/hooks/useInView';
interface AnimatedTextProps {
children: ReactNode;
className?: string;
startClass?: string;
finishClass?: string;
threshold?: number; // New prop
}
export function AnimatedText({
children,
className = '',
startClass,
finishClass,
threshold,
}: AnimatedTextProps) {
const ref = useRef<HTMLDivElement>(null);
const isVisible = useInView(ref, {
threshold: threshold ?? 0.1,
triggerOnce: true,
});
return (
<div
ref={ref}
className={`transition-[opacity, transform] ease-out duration-1000 ${
isVisible ? 'opacity-100' : 'opacity-0'
} ${isVisible ? finishClass : startClass} ${className}`}
>
{children}
</div>
);
}