CircuitScope / frontend /src /components /AnimatedSection.js
Gaurav711's picture
feat: complete live cpu inference, research sweep, blog & production build
2d4e3e5
Raw
History Blame Contribute Delete
922 Bytes
import React, { useRef, useState, useEffect } from 'react';
export const AnimatedSection = ({ children, className = '', delay = 0 }) => {
const ref = useRef(null);
const [isVisible, setIsVisible] = useState(false);
useEffect(() => {
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setIsVisible(true);
observer.disconnect();
}
},
{ threshold: 0.1, rootMargin: '0px 0px -40px 0px' }
);
if (ref.current) observer.observe(ref.current);
return () => observer.disconnect();
}, []);
return (
<div
ref={ref}
className={className}
style={{
opacity: isVisible ? 1 : 0,
transform: isVisible ? 'translateY(0)' : 'translateY(20px)',
transition: `opacity 0.6s ease-out ${delay}ms, transform 0.6s ease-out ${delay}ms`,
}}
>
{children}
</div>
);
};