|
| 1 | +import { useEffect, useRef } from "react"; |
| 2 | +import gsap from "gsap"; |
| 3 | +import { ScrollTrigger } from "gsap/ScrollTrigger"; |
| 4 | + |
| 5 | +const EventsHighlight = () => { |
| 6 | + const containerRef = useRef(null); |
| 7 | + |
| 8 | + const images = [ |
| 9 | + { |
| 10 | + url: "/CodeX-Website/gallery/Community Session/cs1.jpg", |
| 11 | + alt: "Image 1", |
| 12 | + side: "left", |
| 13 | + }, |
| 14 | + { |
| 15 | + url: "/CodeX-Website/gallery/AIML SESSION/aiml1.jpg", |
| 16 | + alt: "Image 2", |
| 17 | + side: "right", |
| 18 | + }, |
| 19 | + { |
| 20 | + url: "/CodeX-Website/gallery//AIML SESSION/aiml6.jpg", |
| 21 | + alt: "Image 3", |
| 22 | + side: "left", |
| 23 | + }, |
| 24 | + { |
| 25 | + url: "/CodeX-Website/gallery/Community Session/cs3.jpg", |
| 26 | + alt: "Image 4", |
| 27 | + side: "right", |
| 28 | + }, |
| 29 | + { |
| 30 | + url: "/CodeX-Website/gallery/HackTober Fest/htf1_1.jpg", |
| 31 | + alt: "Image 5", |
| 32 | + side: "left", |
| 33 | + }, |
| 34 | + { |
| 35 | + url: "/CodeX-Website/gallery/Laser Lock/ll1.jpg", |
| 36 | + alt: "Image 6", |
| 37 | + side: "right", |
| 38 | + }, |
| 39 | + ]; |
| 40 | + |
| 41 | + useEffect(() => { |
| 42 | + gsap.registerPlugin(ScrollTrigger); |
| 43 | + |
| 44 | + // Set up each image animation |
| 45 | + images.forEach((_, index) => { |
| 46 | + const imageSection = containerRef.current.children[index]; |
| 47 | + |
| 48 | + gsap.fromTo( |
| 49 | + imageSection, |
| 50 | + { |
| 51 | + opacity: 1, |
| 52 | + y: "20vh", |
| 53 | + }, |
| 54 | + { |
| 55 | + opacity: 1, |
| 56 | + y: "-100vh", |
| 57 | + ease: "none", |
| 58 | + scrollTrigger: { |
| 59 | + trigger: imageSection, |
| 60 | + start: "top bottom", |
| 61 | + end: "bottom top", |
| 62 | + scrub: 1, |
| 63 | + markers: false, |
| 64 | + }, |
| 65 | + }, |
| 66 | + ); |
| 67 | + }); |
| 68 | + |
| 69 | + return () => { |
| 70 | + ScrollTrigger.getAll().forEach((trigger) => trigger.kill()); |
| 71 | + }; |
| 72 | + }, []); |
| 73 | + |
| 74 | + return ( |
| 75 | + <div className="relative"> |
| 76 | + {/* Fixed description */} |
| 77 | + <div className="sticky top-1/2 z-0 text-center"> |
| 78 | + <h2 className="xs:text-4xl md:text-6xl lg:text-8xl font-bold text-black mb-4 text-white mt-[48vh] tracking-tighter font-black font-poppins"> |
| 79 | + Events Highlight |
| 80 | + </h2> |
| 81 | + </div> |
| 82 | + |
| 83 | + {/* Images container */} |
| 84 | + <div ref={containerRef} className="relative"> |
| 85 | + {images.map((image, index) => ( |
| 86 | + <div |
| 87 | + key={index} |
| 88 | + className={`relative h-[50vh] flex items-center justify-center ${ |
| 89 | + image.side === "left" ? "ml-24" : "mr-24" |
| 90 | + }`} |
| 91 | + > |
| 92 | + <div |
| 93 | + className={`absolute ${ |
| 94 | + image.side === "left" ? "left-0 z-100" : "right-0" |
| 95 | + } xs:w-[20rem] md:w-[30rem]`} |
| 96 | + > |
| 97 | + <img |
| 98 | + src={image.url} |
| 99 | + alt={image.alt} |
| 100 | + className="w-full object-contain rounded-lg shadow-xl" |
| 101 | + /> |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + ))} |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + ); |
| 108 | +}; |
| 109 | + |
| 110 | +export default EventsHighlight; |
0 commit comments