-
Notifications
You must be signed in to change notification settings - Fork 6
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
4b96a68
commit abb7e90
Showing
8 changed files
with
107 additions
and
100 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
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 was deleted.
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,97 @@ | ||
import { useState, useEffect } from 'react' | ||
import { motion, useScroll, useTransform } from 'framer-motion' | ||
import { Logo } from '~/components/images/Logo' | ||
|
||
const articles = [ | ||
{ title: "CSS Scroll Animations", description: "Check out this rad demo", cta: "Follow", image: "https://picsum.photos/1920/1080?random=1" }, | ||
{ title: "Animate on scroll", description: "Works with media queries too", cta: "Check it out", image: "https://picsum.photos/1920/1080?random=2" }, | ||
{ title: "Parallax Effects", description: "Tweak your timings", cta: "Get Styling", image: "https://picsum.photos/1920/1080?random=3" }, | ||
{ title: "Drive Keyframes", description: "CSS alone and...", cta: "No JavaScript", image: "https://picsum.photos/1920/1080?random=4" }, | ||
{ title: "Extra Slides", description: "More content because...", cta: "CSS to the moon", image: "https://picsum.photos/1920/1080?random=5" }, | ||
{ title: "Resize Window", description: "Try resizing the window", cta: "Resize", image: "https://picsum.photos/1920/1080?random=6" }, | ||
{ title: "Browser support", description: "You'll need to be in Chrome", cta: "Do it", image: "https://picsum.photos/1920/1080?random=7" }, | ||
{ title: "Your idea", description: "What would you make?", cta: "Code", image: "https://picsum.photos/1920/1080?random=8" }, | ||
{ title: "Fork", description: "Fork this and make it your own!", cta: "Duplicate", image: "https://picsum.photos/1920/1080?random=9" }, | ||
{ title: "Heart", description: "If you like this, heart it (3x)", cta: "Like", image: "https://picsum.photos/1920/1080?random=10" }, | ||
] | ||
|
||
export function InvertedRevealScroll() { | ||
const [isMobile, setIsMobile] = useState(false) | ||
|
||
useEffect(() => { | ||
const checkMobile = () => setIsMobile(window.innerWidth < 768) | ||
checkMobile() | ||
window.addEventListener('resize', checkMobile) | ||
return () => window.removeEventListener('resize', checkMobile) | ||
}, []) | ||
|
||
return ( | ||
<div className="min-h-screen overflow-x-hidden"> | ||
<main> | ||
{articles.map((article, index) => ( | ||
<Article key={index} {...article} index={index} isMobile={isMobile} /> | ||
))} | ||
</main> | ||
</div> | ||
) | ||
} | ||
|
||
interface ArticleProps { | ||
title: string; | ||
description: string; | ||
cta: string; | ||
image: string; | ||
index: number; | ||
isMobile: boolean; | ||
} | ||
|
||
function Article({ title, description, cta, image, index, isMobile }: ArticleProps) { | ||
const { scrollYProgress } = useScroll() | ||
const brightness = useTransform(scrollYProgress, [0, 0.5, 1], [2, 1, 0.5]) | ||
const clipPath = useTransform( | ||
scrollYProgress, | ||
[0, 1], | ||
['inset(0% 0% 0% 0%)', 'inset(100% 0% 0% 0%)'] | ||
) | ||
|
||
return ( | ||
<motion.article | ||
className={`w-full ${ | ||
isMobile ? 'h-screen grid grid-rows-[calc(100vh-35vh)_35vh]' : 'min-h-screen grid place-items-start relative' | ||
}`} | ||
style={{ zIndex: 10 - index }} | ||
> | ||
<motion.div | ||
className={`${ | ||
isMobile | ||
? 'sticky top-0 left-0 right-0 h-[35vh]' | ||
: 'fixed top-0 right-0 left-[40%] bottom-0 h-screen' | ||
}`} | ||
style={isMobile ? {} : { filter: brightness, clipPath }} | ||
> | ||
<img | ||
src={image} | ||
alt="" | ||
className="object-cover" | ||
sizes="(max-width: 768px) 100vw, 60vw" | ||
/> | ||
</motion.div> | ||
<div | ||
className={`${ | ||
isMobile | ||
? 'bg-white text-center z-20 grid place-items-center content-center gap-2 h-[35vh]' | ||
: 'bg-transparent h-screen w-[40%] grid place-items-center p-4 gap-4 content-center' | ||
}`} | ||
> | ||
<h2 className="uppercase text-4xl m-0">{title}</h2> | ||
<p>{description}</p> | ||
<a | ||
href="#" | ||
className="uppercase font-semibold text-[#fafafa] bg-black px-8 py-4 no-underline tracking-wide text-xl rounded transition-colors hover:bg-[#666]" | ||
> | ||
{cta} | ||
</a> | ||
</div> | ||
</motion.article> | ||
) | ||
} |
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,5 @@ | ||
import { InvertedRevealScroll } from "./InvertedRevealScroll"; | ||
|
||
export default function Index() { | ||
return <InvertedRevealScroll />; | ||
} |