design: add image loading animation
This commit is contained in:
1 parent
3fb92f6e81
commit
ef1d13b06f
1 file changed
+49
-21
@@ -13,7 +13,9 @@
|
|||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import type { Post } from 'lemmy-js-client'
|
import type { Post } from 'lemmy-js-client'
|
||||||
import PostIframe from './PostIframe.svelte'
|
import PostIframe from './PostIframe.svelte'
|
||||||
import { Button, Material } from 'mono-svelte'
|
import { Button, Material, modal } from 'mono-svelte'
|
||||||
|
import { onMount } from 'svelte'
|
||||||
|
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
|
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
|
||||||
export let post: Post
|
export let post: Post
|
||||||
@@ -22,6 +24,12 @@
|
|||||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
||||||
|
|
||||||
let showAltText = false
|
let showAltText = false
|
||||||
|
|
||||||
|
let imageLoaded: boolean | null = null
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
imageLoaded = false
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@@ -36,8 +44,7 @@
|
|||||||
<svelte:element
|
<svelte:element
|
||||||
this={$userSettings.expandImages ? 'button' : 'a'}
|
this={$userSettings.expandImages ? 'button' : 'a'}
|
||||||
href={postLink(post)}
|
href={postLink(post)}
|
||||||
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900
|
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
|
||||||
"
|
|
||||||
data-sveltekit-preload-data="off"
|
data-sveltekit-preload-data="off"
|
||||||
aria-label={post.name}
|
aria-label={post.name}
|
||||||
on:click={() => showImage(bestImageURL(post, false, 2048))}
|
on:click={() => showImage(bestImageURL(post, false, 2048))}
|
||||||
@@ -48,7 +55,8 @@
|
|||||||
<img
|
<img
|
||||||
src={bestImageURL(post, false, 64)}
|
src={bestImageURL(post, false, 64)}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
class="-z-10 absolute top-0 left-0 w-full h-full object-cover blur-xl opacity-40"
|
class="-z-10 absolute top-0 left-0 w-full h-full object-cover blur-xl transition-opacity
|
||||||
|
{imageLoaded === false ? 'opacity-40' : 'opacity-40'}"
|
||||||
/>
|
/>
|
||||||
<picture class="max-h-[inherit]">
|
<picture class="max-h-[inherit]">
|
||||||
<source
|
<source
|
||||||
@@ -72,31 +80,51 @@
|
|||||||
src={bestImageURL(post, false, 2048)}
|
src={bestImageURL(post, false, 2048)}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
class="max-h-[inherit] max-w-full h-auto z-30
|
class="max-h-[inherit] max-w-full h-auto z-30
|
||||||
transition-opacity duration-300 object-contain mx-auto"
|
transition-opacity duration-500 object-contain mx-auto
|
||||||
|
{imageLoaded === false ? 'opacity-0' : 'opacity-100'}"
|
||||||
width={512}
|
width={512}
|
||||||
height={300}
|
height={300}
|
||||||
class:blur-3xl={blur}
|
class:blur-3xl={blur}
|
||||||
alt={post.alt_text ?? ''}
|
alt={post.alt_text ?? ''}
|
||||||
|
on:load={() => (imageLoaded = true)}
|
||||||
/>
|
/>
|
||||||
</picture>
|
</picture>
|
||||||
{#if post.alt_text}
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<Button
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
on:click={(e) => {
|
<div
|
||||||
e.stopPropagation()
|
class="absolute bottom-0 left-0 right-0 flex justify-between items-center
|
||||||
showAltText = !showAltText
|
rounded-full ml-auto w-max m-2 p-0 gap-1
|
||||||
}}
|
*:bg-white *:border *:border-slate-200 *:dark:border-zinc-800 *:dark:bg-zinc-900
|
||||||
class="absolute bottom-0 left-0 text-sm m-2 text-left"
|
*:bg-opacity-70 *:backdrop-blur-md"
|
||||||
|
on:click|stopPropagation={() => {}}
|
||||||
|
>
|
||||||
|
<!-- <Button
|
||||||
|
color="tertiary"
|
||||||
size="sm"
|
size="sm"
|
||||||
rounding="lg"
|
class="aspect-square"
|
||||||
alignment="left"
|
rounding="pill"
|
||||||
|
href={post.url}
|
||||||
|
download
|
||||||
>
|
>
|
||||||
{#if showAltText}
|
<Icon src={ArrowDownTray} size="16" micro />
|
||||||
{post.alt_text}
|
</Button> -->
|
||||||
{:else}
|
{#if post.alt_text}
|
||||||
<span class="font-bold">ALT</span>
|
<Button
|
||||||
{/if}
|
on:click={(e) => {
|
||||||
</Button>
|
e.stopPropagation()
|
||||||
{/if}
|
modal({
|
||||||
|
title: 'Alt',
|
||||||
|
body: post.alt_text ?? '',
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
color="tertiary"
|
||||||
|
size="md"
|
||||||
|
rounding="pill"
|
||||||
|
>
|
||||||
|
ALT
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</svelte:element>
|
</svelte:element>
|
||||||
{/if}
|
{/if}
|
||||||
{:else if (type == 'iframe' || type == 'video') && (view == 'cozy' || view == 'card') && post.url}
|
{:else if (type == 'iframe' || type == 'video') && (view == 'cozy' || view == 'card') && post.url}
|
||||||
|
|||||||
Reference in new issue
Block a user