Skip to content

Commit

Permalink
Add the mascot with scroll animations.
Browse files Browse the repository at this point in the history
  • Loading branch information
toddriley committed Sep 29, 2023
1 parent 8c49abc commit 37c75ad
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 32 deletions.
Binary file added docs/public/mascot.webp
Binary file not shown.
60 changes: 32 additions & 28 deletions docs/src/components/Hero.tsx
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>
</>
);
}
63 changes: 63 additions & 0 deletions docs/src/components/Mascot.tsx
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",
])}
/>
);
}
10 changes: 6 additions & 4 deletions docs/src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export default function Document() {
rel="stylesheet"
/>
</Head>
<body className="flex justify-center">
<div className="w-full max-w-[1300px]">
<Main />
<NextScript />
<body>
<div className="flex justify-center">
<div className="w-full max-w-[1300px] overflow-hidden">
<Main />
<NextScript />
</div>
</div>
</body>
</Html>
Expand Down
20 changes: 20 additions & 0 deletions docs/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ module.exports = {
"logo-tablet": "5px 5px 2px #000",
"logo-desktop": "5px 5px 2px #000",
},
animation: {
"slide-and-fade":
"slide 1s linear calc(var(--page-scroll) * -0.9s) paused," +
"customFade 1s linear calc(var(--literal-scroll) * -0.9s) paused",
},
keyframes: {
slide: {
to: {
transform: "translateY(var(--innerHeight))",
},
},
customFade: {
from: {
opacity: 1,
},
to: {
opacity: 0.2,
},
},
},
},
fontFamily: {
sans: "'Jost', sans-serif",
Expand Down

0 comments on commit 37c75ad

Please sign in to comment.