-
Notifications
You must be signed in to change notification settings - Fork 182
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
Showing
6 changed files
with
149 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,74 @@ | ||
import React, { useState, useEffect, useRef } from 'react' | ||
|
||
const useElementOnScreen = (ref, rootMargin = '0px') => { | ||
const [isIntersecting, setIsIntersecting] = useState(true) | ||
useEffect(() => { | ||
const observer = new IntersectionObserver( | ||
([entry]) => { | ||
setIsIntersecting(entry.isIntersecting) | ||
}, | ||
{ rootMargin } | ||
) | ||
if (ref.current) { | ||
observer.observe(ref.current) | ||
} | ||
return () => { | ||
if (ref.current) { | ||
observer.unobserve(ref.current) | ||
} | ||
} | ||
}, []) | ||
return isIntersecting | ||
} | ||
|
||
const AnimateIn = ({ from, to, children }) => { | ||
const ref = useRef(null) | ||
const onScreen = useElementOnScreen(ref) | ||
const defaultStyles = { | ||
transition: '1000ms ease-in-out', | ||
} | ||
return ( | ||
<div | ||
ref={ref} | ||
style={ | ||
onScreen | ||
? { | ||
...defaultStyles, | ||
...to, | ||
} | ||
: { | ||
...defaultStyles, | ||
...from, | ||
} | ||
} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} | ||
|
||
const FadeIn = ({ children }) => ( | ||
<AnimateIn from={{ opacity: 0 }} to={{ opacity: 1 }}> | ||
{children} | ||
</AnimateIn> | ||
) | ||
|
||
const FadeUp = ({ children }) => ( | ||
<AnimateIn from={{ opacity: 0, translate: '0 2rem' }} to={{ opacity: 1, translate: 'none' }}> | ||
{children} | ||
</AnimateIn> | ||
) | ||
|
||
const ScaleIn = ({ children }) => ( | ||
<AnimateIn from={{ scale: '0' }} to={{ scale: '1' }}> | ||
{children} | ||
</AnimateIn> | ||
) | ||
|
||
const AnimateOnScreen = { | ||
FadeIn, | ||
FadeUp, | ||
ScaleIn, | ||
} | ||
|
||
export default AnimateOnScreen |
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,21 @@ | ||
import React from 'react' | ||
import { motion } from 'framer-motion' | ||
|
||
const ScrollAnimation = ({ children }) => { | ||
return ( | ||
<motion.div | ||
initial={{ opacity: 0, y: 50 }} | ||
whileInView={{ opacity: 1, y: 0 }} | ||
// viewport={{once:true}} | ||
transition={{ | ||
ease: 'linear', | ||
duration: 1, | ||
y: { duration: 0.5 }, | ||
}} | ||
> | ||
{children} | ||
</motion.div> | ||
) | ||
} | ||
|
||
export default ScrollAnimation |
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