-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the mascot with scroll animations.
- Loading branch information
toddriley
committed
Sep 29, 2023
1 parent
8c49abc
commit 37c75ad
Showing
5 changed files
with
121 additions
and
32 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -1,46 +1,50 @@ | ||
import clsx from "clsx"; | ||
import { ButtonList } from "./ButtonList"; | ||
import { Logo } from "./Logo"; | ||
import { Mascot } from "./Mascot"; | ||
|
||
export function Hero() { | ||
return ( | ||
<div | ||
className={clsx([ | ||
"flex", | ||
"justify-between", | ||
"px-2", | ||
"wide-phone:block", | ||
"wide-phone:px-4", | ||
"wide-phone:py-2", | ||
"wide-phone:text-right", | ||
])} | ||
> | ||
<Logo /> | ||
<> | ||
<Mascot /> | ||
<div | ||
className={clsx([ | ||
"flex", | ||
"flex-col", | ||
"justify-between", | ||
"pt-1", | ||
"wide-phone:p-0", | ||
"wide-phone:justify-center", | ||
"wide-phone:items-end", | ||
"px-2", | ||
"wide-phone:block", | ||
"wide-phone:px-4", | ||
"wide-phone:py-2", | ||
"wide-phone:text-right", | ||
])} | ||
> | ||
<p | ||
<Logo /> | ||
<div | ||
className={clsx([ | ||
"font-sans", | ||
"text-[22px]", | ||
"wide-phone:text-[30px]", | ||
"wide-phone:mb-2", | ||
"tablet:text-[40px]", | ||
"desktop:text-[60px]", | ||
"flex", | ||
"flex-col", | ||
"justify-between", | ||
"pt-1", | ||
"wide-phone:p-0", | ||
"wide-phone:justify-center", | ||
"wide-phone:items-end", | ||
])} | ||
> | ||
snapshot testing for | ||
</p> | ||
<ButtonList /> | ||
<p | ||
className={clsx([ | ||
"font-sans", | ||
"text-[22px]", | ||
"wide-phone:text-[30px]", | ||
"wide-phone:mb-2", | ||
"tablet:text-[40px]", | ||
"desktop:text-[60px]", | ||
])} | ||
> | ||
snapshot testing for | ||
</p> | ||
<ButtonList /> | ||
</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,63 @@ | ||
import clsx from "clsx"; | ||
import { useEffect, useRef } from "react"; | ||
|
||
export function Mascot() { | ||
const literalOffsetTop = useRef(0); | ||
|
||
useEffect(() => { | ||
const literalSection = document.getElementById("selfie-is-literal")!; | ||
literalOffsetTop.current = literalSection.offsetTop; | ||
|
||
function setScrollPosition() { | ||
// 0 at the stop of the page, 1 at the bottom of the page | ||
const pageScrollOffset = | ||
window.scrollY / (document.body.offsetHeight - window.innerHeight); | ||
document.body.style.setProperty("--page-scroll", "" + pageScrollOffset); | ||
|
||
// 0 at the top of the page, 1 when the literal section comes into view. Don't exceed 1. | ||
console.log(literalOffsetTop.current); | ||
document.body.style.setProperty( | ||
"--literal-scroll", | ||
"" + Math.min(window.scrollY / literalOffsetTop.current, 1) | ||
); | ||
} | ||
|
||
function setViewportVariables() { | ||
document.body.style.setProperty( | ||
"--innerHeight", | ||
"-" + window.innerHeight + "px" | ||
); | ||
literalOffsetTop.current = literalSection.offsetTop; | ||
} | ||
|
||
setViewportVariables(); | ||
|
||
window.addEventListener("scroll", setScrollPosition, false); | ||
window.addEventListener("resize", setViewportVariables, false); | ||
return () => { | ||
window.removeEventListener("scroll", setScrollPosition); | ||
window.removeEventListener("resize", setViewportVariables); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<img | ||
src="/mascot.webp" | ||
alt="Selfie mascot" | ||
className={clsx([ | ||
"h-[1745px]", | ||
"fixed", | ||
"top-[80px]", | ||
"left-[20px]", | ||
"object-cover", | ||
"object-center", | ||
"block", | ||
"overflow-visible", | ||
"animate-slide-and-fade", | ||
"block", | ||
"z-[-1]", | ||
"opacity-100", | ||
])} | ||
/> | ||
); | ||
} |
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