-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Gabau/Gabau.github.io
- Loading branch information
Showing
7 changed files
with
87 additions
and
17 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
56 changes: 56 additions & 0 deletions
56
gabau.github.io/src/components/animated/RepeatingBanner.tsx
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,56 @@ | ||
import { useGSAP } from "@gsap/react" | ||
import { gsap } from "gsap/gsap-core"; | ||
import { useRef } from "react"; | ||
|
||
/** | ||
* Idea: translate div in the banner left or right | ||
* @returns | ||
*/ | ||
export default function RepeatingBanner({ | ||
children, | ||
count, | ||
width, | ||
height, | ||
duration | ||
}: { | ||
children: JSX.Element, | ||
width: number, | ||
height: number, | ||
count?: number, | ||
duration?: number | ||
}) { | ||
const movingRef = useRef<HTMLDivElement | null>(null); | ||
// const movingRef1 = useRef<HTMLDivElement | null>(null); | ||
// const movingRef2 = useRef<HTMLDivElement | null>(null); | ||
const wrappedCount = (count ?? 5) * 2; | ||
const singleDuration = duration ?? 1; | ||
useGSAP(() => { | ||
const tl = gsap.timeline({ repeat: -1 }); | ||
tl.to(movingRef.current, { | ||
x: `-50%`, | ||
duration: 0.01 | ||
}) | ||
tl.to( | ||
movingRef.current, | ||
{ | ||
x: '0%', | ||
duration: singleDuration * wrappedCount, | ||
ease: 'none', | ||
} | ||
) | ||
}, { | ||
scope: movingRef | ||
}); | ||
|
||
|
||
|
||
return <div className={`relative overflow-clip text-nowrap z-10`} style={{ width, height }}> | ||
<div className="flex flex-row absolute" ref={movingRef}> | ||
{Array.from(Array(wrappedCount).keys()).map((i) => ( | ||
<div key={i}> | ||
{children} | ||
</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
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,16 @@ | ||
import RepeatingBanner from "../../components/animated/RepeatingBanner"; | ||
|
||
|
||
export default function RepeatingBannerPage() { | ||
return ( | ||
<div className="flex flex-col items-center w-full h-full flex-grow justify-center"> | ||
<div className="flex flex-row items-center"> | ||
<RepeatingBanner width={50} count={10} duration={0.2} height={30}> | ||
<div> | ||
Hello World | ||
</div> | ||
</RepeatingBanner> | ||
</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