chore: thumbnail loading optimization

This commit is contained in:
2024-09-06 15:23:22 +02:00
parent f0863b2459
commit b8f135a454
2 changed files with 9 additions and 21 deletions
+2 -11
View File
@@ -8,7 +8,7 @@
:key="i"
>
<div class="stock-text">
<p>{{ vehicleName.replace(/_/g, ' ') }}</p>
<div>{{ vehicleName.replace(/_/g, ' ') }}</div>
<small v-if="vehicleCargo">({{ vehicleCargo }})</small>
</div>
@@ -189,20 +189,11 @@ ul > li > span {
cursor: crosshair;
}
img {
max-height: 60px;
width: auto;
height: auto;
}
img.traction-only {
max-width: 100%;
}
.stock-text {
text-align: center;
color: #aaa;
font-size: 0.9em;
margin-bottom: 0.25em;
padding: 0.25em 0;
}
</style>
+7 -10
View File
@@ -1,5 +1,5 @@
<template>
<div class="vehicle-thumbnail">
<div class="vehicle-thumbnail" :data-load-status="imgStatus">
<img
ref="imgRef"
:src="`https://static.spythere.eu/thumbnails/v2/${imgName}.png`"
@@ -7,7 +7,6 @@
loading="lazy"
data-tooltip-type="VehiclePreviewTooltip"
:data-tooltip-content="vehicleName"
:data-load-status="imgStatus"
@error="onImageError"
@load="onImageLoad"
/>
@@ -15,7 +14,7 @@
</template>
<script setup lang="ts">
import { onMounted, Ref, ref } from 'vue';
import { Ref, ref } from 'vue';
const props = defineProps({
vehicleName: { type: String, required: true },
@@ -29,8 +28,6 @@ const imgRef = ref(null) as Ref<HTMLElement | null>;
const imgStatus = ref('loading');
function onImageError(event: Event) {
console.log('error');
(event.target as HTMLImageElement).src = `/images/${props.fallbackName}.png`;
imgStatus.value = 'error';
}
@@ -47,15 +44,15 @@ function onImageLoad() {
<style lang="scss" scoped>
.vehicle-thumbnail {
position: relative;
&[data-load-status='loading'] {
min-height: 60px;
min-width: 200px;
}
}
img {
opacity: 0;
transition: opacity 100ms ease-in-out;
&[data-load-status='loading'] {
min-height: 60px;
min-width: 150px;
}
}
</style>