1
1
mirror of https://github.com/theoludwig/theoludwig.git synced 2024-11-05 13:01:30 +01:00
.profile/components/design/RevealFade.tsx
Théo LUDWIG 0bbebeab99
Some checks failed
Analyze / analyze (javascript) (push) Failing after 1m24s
Build / build (push) Successful in 3m0s
Lint / lint (push) Successful in 2m6s
Test / test-unit (push) Successful in 1m56s
Test / test-e2e (push) Successful in 3m17s
build(deps): update latest
2023-07-19 00:09:28 +02:00

34 lines
867 B
TypeScript

import { useEffect, useRef } from 'react'
export const RevealFade: React.FC<React.PropsWithChildren> = (props) => {
const { children } = props
const htmlElement = useRef<HTMLDivElement>(null)
useEffect(() => {
const observer = new window.IntersectionObserver(
(entries, observer) => {
for (const entry of entries) {
if (entry.isIntersecting) {
entry.target.className =
'opacity-100 visible translate-y-0 transition-all duration-700 ease-in-out'
observer.unobserve(entry.target)
}
}
},
{
root: null,
rootMargin: '0px',
threshold: 0.28
}
)
observer.observe(htmlElement.current as HTMLDivElement)
}, [])
return (
<div ref={htmlElement} className='invisible -translate-y-7 opacity-0'>
{children}
</div>
)
}