Brought back parallax using only CSS

This commit is contained in:
DrMint 2024-06-08 01:56:48 +02:00
parent 380cc17b92
commit 9c32bff957
7 changed files with 63 additions and 40 deletions

View File

@ -33,7 +33,6 @@
- [Feat] [Payload] Endpoints should provide a simple text-based version of the content (for OG purposes) - [Feat] [Payload] Endpoints should provide a simple text-based version of the content (for OG purposes)
- [Feat] [WebManifest] Add shortcuts https://web.dev/patterns/web-apps/shortcuts - [Feat] [WebManifest] Add shortcuts https://web.dev/patterns/web-apps/shortcuts
- [Feat] [PWA] Rich install UI https://web.dev/patterns/web-apps/richer-install-ui/ - [Feat] [PWA] Rich install UI https://web.dev/patterns/web-apps/richer-install-ui/
- [Feat] Try using CSS instead of JS for parallax effect
- [Feat] More data caching between the CMS and Astro - [Feat] More data caching between the CMS and Astro
- [Feat] [Folders] Support for nameless section - [Feat] [Folders] Support for nameless section
- [Feat] [Scripts] Can't run the scripts using node (ts-node?) - [Feat] [Scripts] Can't run the scripts using node (ts-node?)

View File

@ -20,7 +20,8 @@ const uniqueId = getRandomId();
{/* ------------------------------------------- HTML ------------------------------------------- */} {/* ------------------------------------------- HTML ------------------------------------------- */}
<img <div inert>
<img
id={uniqueId} id={uniqueId}
src={url} src={url}
srcset={sizesToSrcset(sizes)} srcset={sizesToSrcset(sizes)}
@ -31,8 +32,8 @@ const uniqueId = getRandomId();
class="when-no-print" class="when-no-print"
decoding="async" decoding="async"
alt="" alt=""
inert />
/> </div>
{/* ------------------------------------------- CSS -------------------------------------------- */} {/* ------------------------------------------- CSS -------------------------------------------- */}
@ -46,42 +47,59 @@ const uniqueId = getRandomId();
} }
} }
img { @keyframes parallax {
position: absolute; from {
top: 0; transform: translateY(0);
left: 0; }
right: 0;
bottom: 0;
z-index: -9999;
to {
transform: translateY(calc((100cqb - 100lvh) * var(--parallax-amount)));
}
}
div {
container-type: size;
position: absolute;
inset: 0;
z-index: -9999;
overflow: hidden;
animation: fadeIn 3s forwards;
}
img {
width: 100%; width: 100%;
max-height: 100%; max-height: 100%;
min-height: 100lvh;
object-fit: cover; object-fit: cover;
object-position: 50% 0; object-position: 50% 0;
animation: fadeIn 3s forwards;
@media (max-width: 650.5px) {
display: none;
}
mask-image: linear-gradient(to bottom, rgba(0 0 0 / 100%) min(50vh, 50%), transparent), mask-image: linear-gradient(to bottom, rgba(0 0 0 / 100%) min(50vh, 50%), transparent),
linear-gradient(to right, rgba(0 0 0 / 10%), rgba(0 0 0 / 20%) 640px, black 1200px); linear-gradient(to right, rgba(0 0 0 / 20%) 640px, black 1200px);
mask-composite: intersect; mask-composite: intersect;
@supports (animation-timeline: scroll(root)) {
--parallax-amount: 0.4;
animation-name: parallax;
animation-timing-function: linear;
animation-timeline: scroll(root);
}
} }
</style> </style>
{/* ------------------------------------------- JS --------------------------------------------- */} {/* ------------------------------------------- JS --------------------------------------------- */}
<script define:vars={{ uniqueId }} is:inline> <script define:vars={{ uniqueId }} is:inline>
const element = document.getElementById(uniqueId); const img = document.getElementById(uniqueId);
element.style.animationPlayState = "paused"; const parent = img.parentElement;
if (!parent || !img) return;
element.addEventListener( parent.style.animationPlayState = "paused";
img.addEventListener(
"load", "load",
() => { () => {
element.style.animationPlayState = "running"; parent.style.animationPlayState = "running";
}, },
{ once: true, passive: true } { once: true, passive: true }
); );

View File

@ -606,7 +606,8 @@ const { currentTheme } = Astro.locals;
border-radius: 9999px; border-radius: 9999px;
&:hover, &:focus-visible { &:hover,
&:focus-visible {
color: var(--color-base-850); color: var(--color-base-850);
text-decoration-color: var(--color-base-750); text-decoration-color: var(--color-base-750);
outline: 3px solid var(--color-base-750); outline: 3px solid var(--color-base-750);
@ -635,7 +636,8 @@ const { currentTheme } = Astro.locals;
cursor: pointer; cursor: pointer;
border-radius: 9999px; border-radius: 9999px;
&:hover, &:focus-visible { &:hover,
&:focus-visible {
color: var(--color-base-700); color: var(--color-base-700);
outline-color: var(--color-base-700); outline-color: var(--color-base-700);
outline-offset: 4px; outline-offset: 4px;

View File

@ -59,7 +59,8 @@ const { title, icon, class: className, ariaLabel, id } = Astro.props;
height: 1.5em; height: 1.5em;
} }
&:hover, &:focus-visible { &:hover,
&:focus-visible {
box-shadow: inset 0 0.1em 0.1em 0 var(--color-shadow-2); box-shadow: inset 0 0.1em 0.1em 0 var(--color-shadow-2);
translate: unset; translate: unset;
} }

View File

@ -146,7 +146,8 @@ for (const attribute of attributes) {
position: relative; position: relative;
width: unset; width: unset;
&a:hover > #footer > p, &a:focus-visible #footer > p { &a:hover > #footer > p,
&a:focus-visible #footer > p {
color: var(--color-base-750); color: var(--color-base-750);
} }

View File

@ -75,7 +75,8 @@ const title = (() => {
transition-duration: 150ms; transition-duration: 150ms;
transition-property: border-color, color; transition-property: border-color, color;
&:hover, &:focus-visible { &:hover,
&:focus-visible {
color: var(--color-base-750); color: var(--color-base-750);
border-color: var(--color-base-750); border-color: var(--color-base-750);
} }

View File

@ -149,7 +149,8 @@ const { title, language } = (() => {
text-decoration-color: transparent; text-decoration-color: transparent;
} }
&a:hover > #title, &a:focus-visible > #title { &a:hover > #title,
&a:focus-visible > #title {
color: var(--color-base-750); color: var(--color-base-750);
text-decoration-color: var(--color-base-650); text-decoration-color: var(--color-base-650);
} }