feat: improve image loading

This commit is contained in:
Xyphyn committed 2023-09-24 13:44:19 -07:00
1 parent adcf1a6ada
commit 8d03d105e2
9 files changed
+62 -15

No files matched your search

+27 -3
View File
@@ -79,12 +79,35 @@
<svelte:element
this={$userSettings.expandImages ? 'div' : 'a'}
href={postLink(post.post)}
class="container mx-auto z-10 relative {loaded
class="container mx-auto z-10 transition-colors {loaded
? ''
: 'bg-slate-200 dark:bg-zinc-800'} rounded-md w-fit max-h-[70vh]"
: 'bg-slate-200 dark:bg-zinc-800'} rounded-xl max-h-[60vh] relative overflow-hidden"
data-sveltekit-preload-data="off"
aria-label={post.post.name}
>
<picture
class="absolute top-1/2 -translate-y-1/2 left-0 w-full
opacity-30 object-cover scale-[1.2] blur-3xl -z-10"
>
<source
srcset={bestImageURL(post.post, false, 512)}
media="(max-width: 256px)"
/>
<source
srcset={bestImageURL(post.post, false, 512)}
media="(max-width: 512px)"
/>
<!-- svelte-ignore a11y-missing-attribute -->
<img
src={bestImageURL(post.post, false, 1024)}
loading="lazy"
class="w-full h-full object-cover rounded-xl blur-3xl z-50"
width={512}
height={300}
class:blur-3xl={post.post.nsfw && $userSettings.nsfwBlur}
on:load={() => (loaded = true)}
/>
</picture>
<picture class="max-h-[inherit]">
<source
srcset={bestImageURL(post.post, false, 512)}
@@ -98,7 +121,8 @@
<img
src={bestImageURL(post.post, false, 1024)}
loading="lazy"
class="max-h-[inherit] w-auto rounded-md z-30 opacity-0 transition-opacity duration-300"
class="max-h-[inherit] max-w-full h-auto z-30
opacity-0 transition-opacity duration-300 object-contain mx-auto"
class:opacity-100={loaded}
width={512}
height={300}
+1 -1
View File
@@ -47,6 +47,6 @@
</div>
{/if}
<button on:click={() => (open = !open)} class="{$$props.class}">
<button on:click={() => (open = !open)} class="contents {$$props.class}">
<slot />
</button>
+3 -1
View File
@@ -44,7 +44,9 @@
<nav
class="flex flex-row gap-2 items-center sticky top-0 bg-slate-50/80
dark:bg-black/80 backdrop-blur-3xl w-full mx-auto px-4 py-2 z-50 box-border h-16"
dark:bg-black/80 backdrop-blur-3xl w-full mx-auto px-4 py-2 z-50 box-border h-16
"
>
<div class="flex flex-row gap-2 items-center mr-auto">
<a href="/" class="flex flex-row items-center gap-2 logo group">
+1 -1
View File
@@ -23,7 +23,7 @@
gap-1 max-h-[calc(100svh-4rem)] w-full bg-slate-50 dark:bg-black
{$userSettings.expandSidebar
? 'max-w-[25%] resize-x min-w-[12rem]'
: 'w-max max-w-max min-w-max'}"
: 'w-max max-w-max min-w-max'} {$$props.class}"
>
<Button
on:click={() =>