-
Notifications
You must be signed in to change notification settings - Fork 0
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
5e8da64
commit 8e85641
Showing
1 changed file
with
41 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { motion, useScroll, useTransform } from "framer-motion"; | ||
import React, { useRef } from "react"; | ||
|
||
export default function MultiLayerParallax() { | ||
const ref = useRef(null); | ||
const { scrollYProgress } = useScroll({ | ||
target: ref, | ||
offset: ["start start", "end start"], | ||
}); | ||
const backgroundY = useTransform(scrollYProgress, [0, 1], ["0%", "100%"]); | ||
const textY = useTransform(scrollYProgress, [0, 1], ["0%", "200%"]); | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
className="w-full h-screen overflow-hidden relative grid place-items-center" | ||
> | ||
<motion.h1 | ||
style={{ y: textY }} | ||
className="font-bold text-white text-7xl md:text-9xl relative z-10" | ||
> | ||
PARALLAX | ||
</motion.h1> | ||
|
||
<motion.div | ||
className="absolute inset-0 z-0 bg-bottom bg-cover" | ||
style={{ | ||
backgroundImage: `url(/image-full.png)`, | ||
y: backgroundY, | ||
}} | ||
/> | ||
|
||
<div | ||
className="absolute inset-0 z-20 bg-bottom bg-cover" | ||
style={{ | ||
backgroundImage: `url(/image-bottom.png)`, | ||
}} | ||
/> | ||
</div> | ||
); | ||
} |