aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-04-19 16:57:47 -0700
committerFuwn <[email protected]>2024-04-19 16:57:47 -0700
commit659b3d00641ddda5a7a5b4ab58088320071d64af (patch)
tree5cdd2690b62aefa6492abf6d9064267b8c43936a /src/lib
parentrefactor(image): move cdn to image (diff)
downloaddue.moe-659b3d00641ddda5a7a5b4ab58088320071d64af.tar.xz
due.moe-659b3d00641ddda5a7a5b4ab58088320071d64af.zip
feat(BadgePreview): image lazy loading
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/BadgeWall/BadgePreview.svelte18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/lib/BadgeWall/BadgePreview.svelte b/src/lib/BadgeWall/BadgePreview.svelte
index 6515bc19..0f9cab1c 100644
--- a/src/lib/BadgeWall/BadgePreview.svelte
+++ b/src/lib/BadgeWall/BadgePreview.svelte
@@ -1,8 +1,10 @@
<script lang="ts">
+ import { thumbnail } from '$lib/Utility/image.js';
import type { Badge } from '$lib/Database/userBadges';
import { cdn } from '$lib/Utility/image';
import { databaseTimeToDate } from '$lib/Utility/time';
import locale from '$stores/locale';
+ import { onMount } from 'svelte';
import { cubicOut } from 'svelte/easing';
import { tweened } from 'svelte/motion';
@@ -35,6 +37,19 @@
const handleMouseLeave = () => {
$mouse = { x: 0, y: 0 };
};
+
+ onMount(() => {
+ if (badge && badge.image) {
+ const image = new Image();
+
+ image.src = cdn(badge.image) || '';
+
+ image.onload = () => {
+ badgeReference.src = image.src;
+ console.log('loaded');
+ };
+ }
+ });
</script>
{#if badge}
@@ -47,7 +62,7 @@
class="badge-container"
>
<img
- src={cdn(badge.image)}
+ src={cdn(thumbnail(badge.image))}
bind:this={badgeReference}
style="transform: perspective(1000px) rotateX({$mouse.y / 10}deg) rotateY({-$mouse.x /
10}deg);"
@@ -122,6 +137,7 @@
.badge-preview img {
border-radius: 8px;
max-width: 25vh;
+ width: 100%;
}
.badge-container {