-
Notifications
You must be signed in to change notification settings - Fork 1
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
fe5452d
commit 3ca2ea7
Showing
5 changed files
with
289 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
"use client"; | ||
import { motion,useScroll, useTransform } from "framer-motion"; | ||
import Image from "next/image"; | ||
import { useRef } from "react"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
|
||
export const ParallaxScrollSecond = ({ | ||
images, | ||
className, | ||
}: { | ||
images: string[]; | ||
className?: string; | ||
}) => { | ||
const gridRef = useRef<any>(null); | ||
const { scrollYProgress } = useScroll({ | ||
container: gridRef, // remove this if your container is not fixed height | ||
offset: ["start start", "end start"], // remove this if your container is not fixed height | ||
}); | ||
|
||
const translateYFirst = useTransform(scrollYProgress, [0, 1], [0, -200]); | ||
const translateXFirst = useTransform(scrollYProgress, [0, 1], [0, -200]); | ||
const rotateXFirst = useTransform(scrollYProgress, [0, 1], [0, -20]); | ||
|
||
const translateYThird = useTransform(scrollYProgress, [0, 1], [0, -200]); | ||
const translateXThird = useTransform(scrollYProgress, [0, 1], [0, 200]); | ||
const rotateXThird = useTransform(scrollYProgress, [0, 1], [0, 20]); | ||
|
||
const third = Math.ceil(images.length / 3); | ||
|
||
const firstPart = images.slice(0, third); | ||
const secondPart = images.slice(third, 2 * third); | ||
const thirdPart = images.slice(2 * third); | ||
|
||
return ( | ||
<div | ||
className={cn("h-[40rem] w-full items-start overflow-y-auto", className)} | ||
ref={gridRef} | ||
> | ||
<div | ||
className={` | ||
mx-auto grid max-w-5xl grid-cols-1 items-start gap-10 px-10 py-40 | ||
lg:grid-cols-3 | ||
md:grid-cols-2 | ||
`} | ||
ref={gridRef} | ||
> | ||
<div className="grid gap-10"> | ||
{firstPart.map((el, idx) => ( | ||
<motion.div | ||
style={{ | ||
y: translateYFirst, | ||
x: translateXFirst, | ||
rotateZ: rotateXFirst, | ||
}} // Apply the translateY motion value here | ||
key={"grid-1" + idx} | ||
> | ||
<Image | ||
src={el} | ||
className={` | ||
!m-0 h-80 w-full gap-10 rounded-lg object-cover | ||
object-left-top !p-0 | ||
`} | ||
height="400" | ||
width="400" | ||
alt="thumbnail" | ||
/> | ||
</motion.div> | ||
))} | ||
</div> | ||
<div className="grid gap-10"> | ||
{secondPart.map((el, idx) => ( | ||
<motion.div key={"grid-2" + idx}> | ||
<Image | ||
src={el} | ||
className={` | ||
!m-0 h-80 w-full gap-10 rounded-lg object-cover | ||
object-left-top !p-0 | ||
`} | ||
height="400" | ||
width="400" | ||
alt="thumbnail" | ||
/> | ||
</motion.div> | ||
))} | ||
</div> | ||
<div className="grid gap-10"> | ||
{thirdPart.map((el, idx) => ( | ||
<motion.div | ||
style={{ | ||
y: translateYThird, | ||
x: translateXThird, | ||
rotateZ: rotateXThird, | ||
}} | ||
key={"grid-3" + idx} | ||
> | ||
<Image | ||
src={el} | ||
className={` | ||
!m-0 h-80 w-full gap-10 rounded-lg object-cover | ||
object-left-top !p-0 | ||
`} | ||
height="400" | ||
width="400" | ||
alt="thumbnail" | ||
/> | ||
</motion.div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
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,130 @@ | ||
'use client' | ||
import { motion, useScroll, useTransform } from 'framer-motion' | ||
import Image from 'next/image' | ||
import { useRef } from 'react' | ||
|
||
import { cn } from '@/lib/utils' | ||
|
||
import { type Project } from '../Projects' | ||
|
||
export const ParallaxScroll = ({ | ||
projects, | ||
className, | ||
}: { | ||
projects: Project[] | ||
className?: string | ||
}) => { | ||
const gridRef = useRef<any>(null) | ||
const { scrollYProgress } = useScroll({ | ||
container: gridRef, | ||
offset: ['start start', 'end start'], | ||
}) | ||
|
||
const translateFirst = useTransform(scrollYProgress, [0, 1], [0, -200]) | ||
const translateSecond = useTransform(scrollYProgress, [0, 1], [0, 200]) | ||
const translateThird = useTransform(scrollYProgress, [0, 1], [0, -200]) | ||
|
||
const third = Math.ceil(projects.length / 3) | ||
|
||
const firstPart = projects.slice(0, third) | ||
const secondPart = projects.slice(third, 2 * third) | ||
const thirdPart = projects.slice(2 * third) | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
` | ||
h-auto w-full items-start overflow-y-auto | ||
lg:h-[70vh] | ||
`, | ||
className, | ||
)} | ||
ref={gridRef} | ||
> | ||
<div | ||
className={` | ||
grid grid-cols-1 gap-8 | ||
lg:hidden | ||
md:grid-cols-2 | ||
`} | ||
> | ||
{projects.map((el, idx) => ( | ||
<div key={idx} className="relative h-80 w-full"> | ||
<Image | ||
src={el.thumbnail} | ||
className={` | ||
!m-0 h-80 w-full gap-10 rounded-lg object-cover object-left-top | ||
!p-0 | ||
`} | ||
height="400" | ||
width="400" | ||
alt="thumbnail" | ||
/> | ||
</div> | ||
))} | ||
</div> | ||
<div | ||
className={` | ||
mx-auto hidden grid-cols-1 items-start gap-10 px-10 | ||
lg:grid lg:grid-cols-3 | ||
md:grid-cols-2 | ||
`} | ||
ref={gridRef} | ||
> | ||
<div className="grid gap-10"> | ||
{firstPart.map((el, idx) => ( | ||
<motion.div style={{ y: translateFirst }} key={'grid-1' + idx}> | ||
<Image | ||
src={el.thumbnail} | ||
className={` | ||
!m-0 h-80 w-full gap-10 rounded-lg object-cover | ||
object-left-top !p-0 | ||
`} | ||
height="400" | ||
width="400" | ||
alt="thumbnail" | ||
/> | ||
</motion.div> | ||
))} | ||
</div> | ||
<div className="grid gap-10"> | ||
{secondPart.map((el, idx) => ( | ||
<motion.div style={{ y: translateSecond }} key={'grid-2' + idx}> | ||
<Image | ||
src={el.thumbnail} | ||
className={` | ||
!m-0 h-80 w-full gap-10 rounded-lg object-cover | ||
object-left-top !p-0 | ||
`} | ||
height="400" | ||
width="400" | ||
alt="thumbnail" | ||
/> | ||
</motion.div> | ||
))} | ||
</div> | ||
<div className="grid gap-10"> | ||
{thirdPart.map((el, idx) => ( | ||
<motion.div style={{ y: translateThird }} key={'grid-3' + idx}> | ||
<Image | ||
src={el.thumbnail} | ||
className={` | ||
!m-0 h-80 w-full gap-10 rounded-lg object-cover | ||
object-left-top !p-0 | ||
`} | ||
height="400" | ||
width="400" | ||
alt="thumbnail" | ||
/> | ||
</motion.div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |