diff --git a/src/components/index.ts b/src/components/index.ts index 0f52ffe3..4326b3d3 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -2,5 +2,6 @@ export * from './apply-button' export * from './aura-circle' export * from './floating-button' export * from './glass-card' +export * from './scroll-reveal-container' export * from './section' export * from './seo' diff --git a/src/components/scroll-reveal-container/index.ts b/src/components/scroll-reveal-container/index.ts new file mode 100644 index 00000000..60e8a3b2 --- /dev/null +++ b/src/components/scroll-reveal-container/index.ts @@ -0,0 +1 @@ +export * from './scroll-reveal-container' diff --git a/src/components/scroll-reveal-container/scroll-reveal-container.module.scss b/src/components/scroll-reveal-container/scroll-reveal-container.module.scss new file mode 100644 index 00000000..77b00211 --- /dev/null +++ b/src/components/scroll-reveal-container/scroll-reveal-container.module.scss @@ -0,0 +1,19 @@ +@keyframes animate { + 0% { + opacity: 0; + transform: translate3d(0px, 50px, 0px); + } + 100% { + opacity: 1; + transform: translate3d(0px, 0px, 0px); + } +} + +.box { + opacity: 0; +} + +.visible { + animation: 0.5s ease-in-out 0s 1 normal forwards running animate; + opacity: 1; +} diff --git a/src/components/scroll-reveal-container/scroll-reveal-container.tsx b/src/components/scroll-reveal-container/scroll-reveal-container.tsx new file mode 100644 index 00000000..8fcd5687 --- /dev/null +++ b/src/components/scroll-reveal-container/scroll-reveal-container.tsx @@ -0,0 +1,38 @@ +import clsx from 'clsx' +import { PropsWithChildren, useEffect } from 'react' + +import * as css from './scroll-reveal-container.module.scss' + +interface Props extends PropsWithChildren { + className?: string +} + +export const ScrollRevealContainer = ({ className = '', children }: Props) => { + useEffect(() => { + const initObserver = () => { + const options = { + root: null, + threshold: 0.2, + } + + const observerCallback: IntersectionObserverCallback = (entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting) { + entry.target.classList.add(css.visible) + } + }) + } + + return new IntersectionObserver(observerCallback, options) + } + + const myElements = document.querySelectorAll('.animateBox') + const observer = initObserver() + + myElements.forEach((element) => { + observer.observe(element) + }) + }, [children]) + + return
{qna.question}
- -{qna.answer}
-{qna.question}
+ +{qna.answer}
+