Skip to content

Commit

Permalink
🔧 Fixed loader
Browse files Browse the repository at this point in the history
  • Loading branch information
nwrenger committed Apr 12, 2024
1 parent b0cad35 commit 50ec740
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/routes/ImageLoader.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
<script lang="ts">
import { onMount } from 'svelte';
export let src: string;
export let alt = '';
export let width = 'w-full';
export let height = 'h-full';
export let ratio = 'aspect-auto';
export let rounded = 'rounded-lg';
const base = `${width} ${height} ${ratio} ${rounded}`;
const base = `${width} ${height} ${rounded}`;
let loaded = false;
let mounted = false;
function handleLoad() {
loaded = true;
}
onMount(() => (mounted = true));
</script>

{#if !loaded}
<div class="{base} aspect-square placeholder animate-pulse" />
<div class="{base} h-auto placeholder animate-pulse" />
{/if}

{#if mounted}
<img
{src}
{alt}
on:load={handleLoad}
class="{base} object-cover shadow-md {!loaded ? 'hidden' : ''}"
/>
{/if}
<img
{src}
{alt}
on:load={handleLoad}
class="{base} object-cover shadow-md {!loaded ? 'hidden' : ''}"
/>

0 comments on commit 50ec740

Please sign in to comment.