-
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.
animate headlines and add highlight briefs
- Loading branch information
1 parent
fab723b
commit 9b67aa7
Showing
9 changed files
with
141 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useInView } from "react-intersection-observer"; | ||
import { HighlightInfo } from "."; | ||
|
||
type Props = { | ||
highlight: HighlightInfo; | ||
}; | ||
|
||
export default function BriefCard({ highlight }: Props) { | ||
const { ref: briefRef, inView: briefInView } = useInView({ | ||
threshold: 0.5, // How much visible to trigger | ||
triggerOnce: true, | ||
}); | ||
|
||
return ( | ||
<div ref={briefRef} className="flex w-full p-1 sm:w-1/2 sm:p-2"> | ||
<div className="flex flex-col px-0 py-4 sm:px-4"> | ||
<h1 className="-mb-2 ms-4 text-4xl font-bold text-primaryColor sm:text-5xl"> | ||
{highlight.headline} | ||
</h1> | ||
<p className="w-full flex-grow rounded-lg bg-primaryColor px-2 py-4 text-2xl text-primaryTextColor shadow-md sm:rounded-xl sm:text-3xl"> | ||
{highlight.brief.split(" ").map((word, index) => ( | ||
<span | ||
key={index} | ||
className={`${briefInView ? "opacity-100" : "opacity-0"} inline-block transition-opacity duration-500`} | ||
style={{ | ||
transitionDelay: `${index * 0.1}s`, | ||
}} | ||
> | ||
{word} | ||
</span> | ||
))} | ||
</p> | ||
</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,54 @@ | ||
import { HighlightInfo } from "."; | ||
import { useEffect, useRef, useState } from "react"; | ||
|
||
type Props = { | ||
highlight: HighlightInfo; | ||
}; | ||
|
||
export default function Headlines({ highlight }: Props) { | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
const [headlineWidth, setHeadlineWidth] = useState<number>(0); | ||
|
||
// Update scrollY on scroll | ||
useEffect(() => { | ||
const handleScroll = () => { | ||
if (!containerRef.current) return; | ||
const clientRect = containerRef.current.getBoundingClientRect(); | ||
const percentage = | ||
(100 / clientRect.height) * | ||
(clientRect.height - clientRect.bottom); | ||
// add 5% to fill up sooner | ||
setHeadlineWidth(Math.min(Math.max(percentage + 5, 0), 100)); | ||
}; | ||
|
||
window.addEventListener("scroll", handleScroll); | ||
return () => { | ||
window.removeEventListener("scroll", handleScroll); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div ref={containerRef} className="flex h-[1000px] flex-col"> | ||
{/* Headline image */} | ||
<div className="sticky top-0 -z-10 flex justify-center"> | ||
<div className="relative flex justify-start"> | ||
<img | ||
className="w-screen max-w-[800px]" | ||
src={highlight.headlineImages[0]} | ||
/> | ||
<div | ||
className="absolute left-0 top-0 overflow-x-hidden" | ||
style={{ | ||
width: headlineWidth + "%", | ||
}} | ||
> | ||
<img | ||
className="w-screen max-w-[800px]" | ||
src={highlight.headlineImages[1]} | ||
/> | ||
</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
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
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