-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef3c3a8
commit 75b7ef0
Showing
11 changed files
with
186 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './scroll-reveal-container' |
19 changes: 19 additions & 0 deletions
19
src/components/scroll-reveal-container/scroll-reveal-container.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
38 changes: 38 additions & 0 deletions
38
src/components/scroll-reveal-container/scroll-reveal-container.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <div className={clsx('animateBox', css.box, className)}>{children}</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters