From f5cd56ce861c8c0a931744ae6cf2b96e9c8bca06 Mon Sep 17 00:00:00 2001 From: melMass Date: Fri, 28 Jul 2023 22:14:22 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=8E=A8=20use=20image=20ratio=20for?= =?UTF-8?q?=20imagefeed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/imageFeed.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/web/imageFeed.js b/web/imageFeed.js index 824d1ea..4a2cf4b 100644 --- a/web/imageFeed.js +++ b/web/imageFeed.js @@ -227,7 +227,7 @@ app.registerExtension({ Object.assign(img.style, { width: '100%', height: '100%', - objectFit: 'scale-down', + objectFit: 'cover', }) img.src = `/view?filename=${encodeURIComponent(src.filename)}&type=${ @@ -238,6 +238,10 @@ app.registerExtension({ console.debug(img.src) + img.onload = () => { + but.style.width = `${120 * (img.naturalWidth / img.naturalHeight)}px` + } + but.onclick = () => { lightboxContainer.style.display = 'flex' // add the same image to the lightbox @@ -284,9 +288,11 @@ app.registerExtension({ if (history.outputs) { for (const key of Object.keys(history.outputs)) { console.debug(key) - for (const im of history.outputs[key].images) { - console.debug(im) - createImageBtn(im) + if (history.outputs[key].images) { + for (const im of history.outputs[key].images) { + console.debug(im) + createImageBtn(im) + } } } // for (const src of outputs.outputs.images) {