From 7949c3ce5e0ca837fd681af632a4236c90b874cc Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 15 Nov 2023 17:44:08 +0100 Subject: [PATCH] Improve image load transition for faster loading times --- src/lib/components/LazyImage.svelte | 38 +++++++++++++++--------- src/routes/plants/[plant]/TempBar.svelte | 2 +- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/lib/components/LazyImage.svelte b/src/lib/components/LazyImage.svelte index 8e8fdd6..c1c9ec0 100644 --- a/src/lib/components/LazyImage.svelte +++ b/src/lib/components/LazyImage.svelte @@ -15,14 +15,31 @@ let imgref: Img; let loaded: boolean = false; + let quickloaded: boolean = false; + let loadStart = Date.now(); onMount(() => { - if (imgref && imgref.complete) loaded = true; + loadStart = Date.now(); + if (imgref && imgref.complete) quickloaded = true; }); - (loaded = true)} /> -
+ { + if (Date.now() - loadStart > 500) { + console.log("slow"); + loaded = true; + } else { + console.log("quick"); + quickloaded = true; + } + }} +/> +