diff --git a/components/MultiLayerParallex.js b/components/MultiLayerParallex.js index 92e847b..36dede3 100644 --- a/components/MultiLayerParallex.js +++ b/components/MultiLayerParallex.js @@ -1,41 +1,70 @@ -import { motion, useScroll, useTransform } from "framer-motion"; -import React, { useRef } from "react"; +import React, { useRef, useEffect } from "react"; -export default function MultiLayerParallax() { +const 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%"]); + const animationFrameRef = useRef(null); + + useEffect(() => { + const observer = new IntersectionObserver( + ([entry]) => { + const updateProgress = () => { + const progress = 1 - entry.intersectionRatio; + ref.current.style.setProperty("--scroll-progress", progress); + animationFrameRef.current = null; // Clear the animation frame reference + }; + + if (!animationFrameRef.current) { + animationFrameRef.current = requestAnimationFrame(updateProgress); + } + }, + { threshold: Array.from({ length: 101 }, (_, i) => i / 100) } + ); + + observer.observe(ref.current); + return () => { + observer.disconnect(); + if (animationFrameRef.current) { + cancelAnimationFrame(animationFrameRef.current); + } + }; + }, []); return (
- PARALLAX - - - +
-
); -} +}; + +export default MultiLayerParallax; diff --git a/pages/testenv/index.js b/pages/testenv/index.js new file mode 100644 index 0000000..de4675e --- /dev/null +++ b/pages/testenv/index.js @@ -0,0 +1,58 @@ +import { motion, useScroll, useTransform } from "framer-motion"; +import React, { useRef } from "react"; + +export default function ParallaxTest() { + const ref = useRef(null); + + // Use useScroll to track the scroll progress of the ref element + const { scrollYProgress } = useScroll({ + target: ref, + offset: ["start start", "end end"], + }); + + // Transform the Y position based on scroll progress + const imageY = useTransform(scrollYProgress, [0, 1], ["0%", "-50%"]); + + return ( +
+ {/* Scrollable container */} +
+ {/* Parallax Image */} + + + {/* Foreground Text */} +

+ Scroll to see the Parallax Effect +

+
+ {/* Additional content to ensure scrolling */} +
+

More content below...

+
+
+ ); +} diff --git a/pages/work2/index.js b/pages/work2/index.js index 52ec9f8..72e7ee6 100644 --- a/pages/work2/index.js +++ b/pages/work2/index.js @@ -1,9 +1,65 @@ +import MultiLayerParallax from "../../components/MultiLayerParallex"; +import { Inter } from "next/font/google"; + +const inter = Inter({ subsets: ["latin"] }); + const work2 = () => { - return( -
- work2 -
- ) + return ( +
+ {/* Parallax Section */} +
+ +
+ + {/* Content Section */} +
+
+

+ Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsam quae + earum nobis quasi repellat. Amet facere nulla dolorum accusantium + sit dolores odio excepturi facilis laboriosam officiis dolorem, + nobis reprehenderit molestiae. +

+

+ Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsam quae + earum nobis quasi repellat. Amet facere nulla dolorum accusantium + sit dolores odio excepturi facilis laboriosam officiis dolorem, + nobis reprehenderit molestiae. +

+

+ Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsam quae + earum nobis quasi repellat. Amet facere nulla dolorum accusantium + sit dolores odio excepturi facilis laboriosam officiis dolorem, + nobis reprehenderit molestiae. +

+

+ Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsam quae + earum nobis quasi repellat. Amet facere nulla dolorum accusantium + sit dolores odio excepturi facilis laboriosam officiis dolorem, + nobis reprehenderit molestiae. +

+

+ Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsam quae + earum nobis quasi repellat. Amet facere nulla dolorum accusantium + sit dolores odio excepturi facilis laboriosam officiis dolorem, + nobis reprehenderit molestiae. +

+

+ Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsam quae + earum nobis quasi repellat. Amet facere nulla dolorum accusantium + sit dolores odio excepturi facilis laboriosam officiis dolorem, + nobis reprehenderit molestiae. +

+

+ Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsam quae + earum nobis quasi repellat. Amet facere nulla dolorum accusantium + sit dolores odio excepturi facilis laboriosam officiis dolorem, + nobis reprehenderit molestiae. +

+
+
+
+ ); } -export default work2; \ No newline at end of file +export default work2; diff --git a/public/image-bottom.png b/public/image-bottom.png new file mode 100644 index 0000000..007c76d Binary files /dev/null and b/public/image-bottom.png differ diff --git a/public/image-full.png b/public/image-full.png new file mode 100644 index 0000000..2013751 Binary files /dev/null and b/public/image-full.png differ