-
Notifications
You must be signed in to change notification settings - Fork 479
gsap basic functions #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
600626c
999c33b
6974dac
660cc7f
2eea240
e55def2
5bc3e3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,5 +1,22 @@ | ||||
| import { useGSAP } from "@gsap/react"; | ||||
| import gsap from "gsap"; | ||||
|
|
||||
| const GsapStagger = () => { | ||||
| // TODO: Implement the gsap.stagger() method | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the obsolete TODO comment. The stagger animation is now fully implemented, so the TODO comment should be removed. 🔎 Proposed fix- // TODO: Implement the gsap.stagger() method📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
| useGSAP(() => { | ||||
| gsap.to(".stagger-box", { | ||||
| y: 200, | ||||
| repeat: -1, | ||||
| yoyo: true, | ||||
| ease: "power1.inOut", | ||||
| rotate: 180, | ||||
| duration: 1, | ||||
| stagger: { | ||||
| amount: 0.4, | ||||
| ease: "power1.inOut", | ||||
| } | ||||
| }) | ||||
| }, []) | ||||
|
|
||||
| return ( | ||||
| <main> | ||||
|
|
@@ -32,13 +49,13 @@ const GsapStagger = () => { | |||
|
|
||||
| <div className="mt-20"> | ||||
| <div className="flex gap-5"> | ||||
| <div className="w-20 h-20 bg-indigo-200 rounded-lg stagger-box" /> | ||||
| <div className="w-20 h-20 bg-indigo-300 rounded-lg stagger-box" /> | ||||
| <div className="w-20 h-20 bg-indigo-400 rounded-lg stagger-box" /> | ||||
| <div className="w-20 h-20 bg-indigo-500 rounded-lg stagger-box" /> | ||||
| <div className="w-20 h-20 bg-indigo-600 rounded-lg stagger-box" /> | ||||
| <div className="w-20 h-20 bg-indigo-700 rounded-lg stagger-box" /> | ||||
| <div className="w-20 h-20 bg-indigo-800 rounded-lg stagger-box" /> | ||||
| <div className="w-20 h-20 bg-indigo-200 rounded-lg stagger-box border-t-4 border-t-red-500" /> | ||||
| <div className="w-20 h-20 bg-indigo-300 rounded-lg stagger-box border-t-4 border-t-red-500" /> | ||||
| <div className="w-20 h-20 bg-indigo-400 rounded-lg stagger-box border-t-4 border-t-red-500" /> | ||||
| <div className="w-20 h-20 bg-indigo-500 rounded-lg stagger-box border-t-4 border-t-red-500" /> | ||||
| <div className="w-20 h-20 bg-indigo-600 rounded-lg stagger-box border-t-4 border-t-red-500" /> | ||||
| <div className="w-20 h-20 bg-indigo-700 rounded-lg stagger-box border-t-4 border-t-red-500" /> | ||||
| <div className="w-20 h-20 bg-indigo-800 rounded-lg stagger-box border-t-4 border-t-red-500" /> | ||||
| </div> | ||||
| </div> | ||||
| </main> | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,6 +1,24 @@ | ||||
| import { useGSAP } from "@gsap/react"; | ||||
| import gsap from "gsap"; | ||||
|
|
||||
| const GsapText = () => { | ||||
| // TODO: Implement gsap text animation | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove outdated TODO comment. The GSAP text animation has been implemented, so this TODO comment is no longer relevant and should be removed. 🔎 Proposed fix- // TODO: Implement gsap text animation📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
| useGSAP(() => { | ||||
| gsap.to("#text", { | ||||
| opacity: 1, | ||||
| y: 0, | ||||
| }) | ||||
| gsap.fromTo(".para", { | ||||
| opacity:0, | ||||
| y: 60, | ||||
| }, { | ||||
| opacity: 1, | ||||
| y: 0, | ||||
| delay: 0.5, | ||||
| stagger: 0.4, | ||||
| }) | ||||
|
|
||||
| }, []) | ||||
| return ( | ||||
| <main> | ||||
| <h1 id="text" className="opacity-0 translate-y-10"> | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,31 @@ | ||
| import { useGSAP } from "@gsap/react"; | ||
| import gsap from "gsap"; | ||
|
|
||
| const GsapTimeline = () => { | ||
| // TODO: Implement the gsap timeline | ||
| const timeLine = gsap.timeline({ | ||
| repeat: -1, repeatDelay: 1, yoyo: true, | ||
| }); | ||
|
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Timeline recreated on every render causing memory leaks. The timeline is created at the component's top level, which means it's recreated on every render. This causes:
🔎 Recommended fix using useRefImport -import { useGSAP } from "@gsap/react";
+import { useGSAP } from "@gsap/react";
+import { useRef } from "react";
import gsap from "gsap";
const GsapTimeline = () => {
// TODO: Implement the gsap timeline
- const timeLine = gsap.timeline({
- repeat: -1, repeatDelay: 1, yoyo: true,
- });
+ const timelineRef = useRef();
+
useGSAP(() => {
+ timelineRef.current = gsap.timeline({
+ repeat: -1, repeatDelay: 1, yoyo: true,
+ });
- timeLine.to("#yellow-box", {
+ timelineRef.current.to("#yellow-box", {
x: 200,
rotation: 360,
borderRadius: "100%",
ease: 'power1.inOut',
backgroundColor: "green"
})
- timeLine.to("#yellow-box", {
+ timelineRef.current.to("#yellow-box", {
x: 0,
y: 100,
backgroundColor: "red",
ease: "power1.inOut"
})
- timeLine.to('#yellow-box', {
+ timelineRef.current.to('#yellow-box', {
x:200,
ease: "power1.inOut",
backgroundColor: "blue"
})
}, []);And update the button to use the ref: <button onClick={() => {
- if(timeLine.paused()) {
- timeLine.play();
+ if(timelineRef.current.paused()) {
+ timelineRef.current.play();
} else {
- timeLine.pause();
+ timelineRef.current.pause();
}
}}>Play/Pause</button>🤖 Prompt for AI Agents |
||
| useGSAP(() => { | ||
| timeLine.to("#yellow-box", { | ||
| x: 200, | ||
| rotation: 360, | ||
| borderRadius: "100%", | ||
| ease: 'power1.inOut', | ||
| backgroundColor: "green" | ||
| }) | ||
| timeLine.to("#yellow-box", { | ||
| x: 0, | ||
| y: 100, | ||
| backgroundColor: "red", | ||
| ease: "power1.inOut" | ||
| }) | ||
| timeLine.to('#yellow-box', { | ||
| x:200, | ||
| ease: "power1.inOut", | ||
| backgroundColor: "blue" | ||
| }) | ||
| }, []); | ||
|
|
||
| return ( | ||
| <main> | ||
|
|
@@ -35,9 +61,15 @@ const GsapTimeline = () => { | |
| </p> | ||
|
|
||
| <div className="mt-20 space-y-10"> | ||
| <button onClick={() => {}}>Play/Pause</button> | ||
| <button onClick={() => { | ||
| if(timeLine.paused()) { | ||
| timeLine.play(); | ||
| } else { | ||
| timeLine.pause(); | ||
| } | ||
| }}>Play/Pause</button> | ||
|
|
||
| <div id="yellow-box" className="w-20 h-20 bg-yellow-500 rounded-lg" /> | ||
| <div id="yellow-box" className="w-10 h-10 bg-yellow-500 rounded-lg" /> | ||
| </div> | ||
| </main> | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect opacity value.
The opacity property should be between 0 and 1, not 100. While this will be clamped to 1, it indicates incorrect usage and should be fixed.
🔎 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents