1
1
mirror of https://github.com/theoludwig/theoludwig.git synced 2024-09-19 14:05:53 +02:00
.profile/components/design/RevealFade.tsx

38 lines
933 B
TypeScript
Raw Normal View History

"use client"
import { useEffect, useRef } from "react"
2021-04-18 01:56:23 +02:00
export type RevealFadeProps = React.PropsWithChildren
export const RevealFade = (props: RevealFadeProps): JSX.Element => {
2021-04-18 01:56:23 +02:00
const { children } = props
const htmlElement = useRef<HTMLDivElement>(null)
useEffect(() => {
const observer = new window.IntersectionObserver(
(entries, observer) => {
2023-07-19 00:09:28 +02:00
for (const entry of entries) {
2021-04-18 01:56:23 +02:00
if (entry.isIntersecting) {
2021-12-04 15:52:51 +01:00
entry.target.className =
"opacity-100 visible translate-y-0 transition-all duration-700 ease-in-out"
2021-04-18 01:56:23 +02:00
observer.unobserve(entry.target)
}
2023-07-19 00:09:28 +02:00
}
2021-04-18 01:56:23 +02:00
},
{
root: null,
rootMargin: "0px",
threshold: 0.28,
},
2021-04-18 01:56:23 +02:00
)
observer.observe(htmlElement.current as HTMLDivElement)
}, [])
return (
<div ref={htmlElement} className="invisible -translate-y-7 opacity-0">
2021-12-04 15:52:51 +01:00
{children}
</div>
2021-04-18 01:56:23 +02:00
)
}