Skip to content

Commit

Permalink
Add: parallax effect foundation :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham-Patel07 committed Aug 31, 2024
1 parent 5e8da64 commit 8e85641
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions components/MultiLayerParallex.js
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>
);
}

0 comments on commit 8e85641

Please sign in to comment.