Skip to content

Commit 48c20f5

Browse files
committed
Added comments
1 parent 824b655 commit 48c20f5

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/components/ImageList.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const ImageList = () => {
1616
<button
1717
href="#last-image"
1818
onClick={() => lenis.scrollTo("#last-image", { lerp: 0.01 })}
19+
// lenis is the object returned from useLenis, and it has a method called scrollTo() that takes two arguments, the first is the id of the element you want to scroll to, and the second is the options object, here we set the lerp to 0.01 to make the scroll slower
1920
className="bg-white text-black capitalize p-4 font-semibold text-xl mt-16 hover:bg-white/90"
2021
>
2122
scroll to anchor

src/components/Parallax.jsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,36 @@ import { useWindowSize } from "@studio-freight/hamo";
55
import { ScrollTrigger } from "gsap/ScrollTrigger";
66

77
export function Parallax({ className, children, speed = 1, id = "parallax" }) {
8-
const trigger = useRef();
9-
const target = useRef();
10-
const timeline = useRef();
8+
const trigger = useRef(); // this is the element that will trigger the animation
9+
const target = useRef(); // this is the element that will be animated
10+
const timeline = useRef(); // this is the timeline of the animation that will be created by gsap
1111
const { width: windowWidth } = useWindowSize();
1212

1313
useEffect(() => {
1414
gsap.registerPlugin(ScrollTrigger);
1515
const y = windowWidth * speed * 0.1;
16+
// here the y is the distance the element will move in px when the trigger is at the top of the viewport and the element is at the bottom of the viewport
17+
1618

1719
const setY = gsap.quickSetter(target.current, "y", "px");
20+
// here we create a function that will set the y position of the element, The gsap.quickSetter() method is a handy way to create a function that will set a specific property on a specific object. In this case, we want to set the y property of the target element in pixels.
1821

1922
timeline.current = gsap.timeline({
2023
scrollTrigger: {
2124
id: id,
22-
trigger: trigger.current,
23-
scrub: true,
24-
start: "top bottom",
25-
end: "bottom top",
25+
trigger: trigger.current, // this is the element that will trigger the animation
26+
scrub: true, // this will make the animation smooth and not jumpy when scrolling up and down the page
27+
start: "top bottom", // this means the animation will start when the top of the trigger element reaches the bottom of the viewport
28+
end: "bottom top", // this means the animation will end when the bottom of the trigger element reaches the top of the viewport
2629
onUpdate: (e) => {
2730
setY(e.progress * y);
2831
},
32+
// markers: true,
2933
},
3034
});
3135

3236
return () => {
33-
timeline?.current?.kill();
37+
timeline?.current?.kill(); // this will kill the animation when the component unmounts
3438
};
3539
}, [id, speed, windowWidth]);
3640

src/components/SmoothScrolling.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function SmoothScrolling({ children }) {
66
<ReactLenis
77
root
88
options={{ lerp: 0.0001, duration: 1.5, smoothTouch: true }}
9-
direction={-1}
9+
// here the lerp is the speed of the scroll
1010
>
1111
{children}
1212
</ReactLenis>

0 commit comments

Comments
 (0)