smaller width, height
This commit is contained in:
parent
99cadbb106
commit
3d73849a28
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="[$style.root, { [$style.cover]: cover }]" :title="title ?? ''">
|
<div ref="root" :class="[$style.root, { [$style.cover]: cover }]" :title="title ?? ''">
|
||||||
<TransitionGroup
|
<TransitionGroup
|
||||||
:duration="defaultStore.state.animation && props.transition?.duration || undefined"
|
:duration="defaultStore.state.animation && props.transition?.duration || undefined"
|
||||||
:enter-active-class="defaultStore.state.animation && props.transition?.enterActiveClass || undefined"
|
:enter-active-class="defaultStore.state.animation && props.transition?.enterActiveClass || undefined"
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
:leave-from-class="defaultStore.state.animation && props.transition?.leaveFromClass || undefined"
|
:leave-from-class="defaultStore.state.animation && props.transition?.leaveFromClass || undefined"
|
||||||
>
|
>
|
||||||
<canvas v-show="hide" key="canvas" ref="canvas" :class="$style.canvas" :width="canvasWidth" :height="canvasHeight" :title="title ?? undefined"/>
|
<canvas v-show="hide" key="canvas" ref="canvas" :class="$style.canvas" :width="canvasWidth" :height="canvasHeight" :title="title ?? undefined"/>
|
||||||
<img v-show="!hide" key="img" :height="height" :width="width" :class="$style.img" :src="src ?? undefined" :title="title ?? undefined" :alt="alt ?? undefined" loading="eager" @load="onLoad"/>
|
<img v-show="!hide" key="img" :height="imgHeight" :width="imgWidth" :class="$style.img" :src="src ?? undefined" :title="title ?? undefined" :alt="alt ?? undefined" loading="eager" @load="onLoad"/>
|
||||||
</TransitionGroup>
|
</TransitionGroup>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -65,16 +65,19 @@ const props = withDefaults(defineProps<{
|
||||||
|
|
||||||
const viewId = uuid();
|
const viewId = uuid();
|
||||||
const canvas = shallowRef<HTMLCanvasElement>();
|
const canvas = shallowRef<HTMLCanvasElement>();
|
||||||
|
const root = shallowRef<HTMLDivElement>();
|
||||||
let loaded = $ref(false);
|
let loaded = $ref(false);
|
||||||
let canvasWidth = $ref(props.width);
|
let canvasWidth = $ref(64);
|
||||||
let canvasHeight = $ref(props.height);
|
let canvasHeight = $ref(64);
|
||||||
|
let imgWidth = $ref(props.width);
|
||||||
|
let imgHeight = $ref(props.height);
|
||||||
const hide = computed(() => !loaded || props.forceBlurhash);
|
const hide = computed(() => !loaded || props.forceBlurhash);
|
||||||
|
|
||||||
function onLoad() {
|
function onLoad() {
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
watch([() => props.width, () => props.height], () => {
|
watch([() => props.width, () => props.height, root], () => {
|
||||||
const ratio = props.width / props.height;
|
const ratio = props.width / props.height;
|
||||||
if (ratio > 1) {
|
if (ratio > 1) {
|
||||||
canvasWidth = Math.round(64 * ratio);
|
canvasWidth = Math.round(64 * ratio);
|
||||||
|
@ -83,6 +86,10 @@ watch([() => props.width, () => props.height], () => {
|
||||||
canvasWidth = 64;
|
canvasWidth = 64;
|
||||||
canvasHeight = Math.round(64 / ratio);
|
canvasHeight = Math.round(64 / ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clientWidth = root.value?.clientWidth ?? 300;
|
||||||
|
imgWidth = clientWidth;
|
||||||
|
imgHeight = Math.round(clientWidth / ratio);
|
||||||
}, {
|
}, {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue