Skip to content

Commit a4a73ae

Browse files
committed
fix: image aspect-radio
1 parent 40fca21 commit a4a73ae

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

main.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function createWindow() {
2525
// frame: false,
2626
skipTaskbar: false,
2727
transparent: false,
28+
backgroundColor: "#1C1917",
2829

2930
resizable: true,
3031
maximizable: true,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "photolisting",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"main": "main.js",
55
"scripts": {
66
"vite-dev": "cross-env NODE_ENV=dev vite",

src/components/Lightbox.vue

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div
3-
class="absolute left-0 top-0 z-20 flex h-full min-h-0 w-screen items-center justify-center overflow-hidden p-5 transition-all"
3+
class="absolute left-0 top-0 z-20 flex h-full min-h-0 w-screen items-center justify-center overflow-hidden p-5 transition-opacity"
44
:class="formOpen ? '' : 'pointer-events-none opacity-0'"
55
tabindex="0"
66
v-focus="formOpen"
@@ -58,6 +58,13 @@ export default {
5858
};
5959
},
6060
mounted() {
61+
window.addEventListener("resize", () => {
62+
if (this.index >= 0 && this.index < this.files.length) {
63+
const f = this.files[this.index];
64+
this.aspectRatioDetection(f);
65+
}
66+
});
67+
6168
this.loadImage();
6269
},
6370
methods: {
@@ -68,8 +75,7 @@ export default {
6875
const f = this.files[this.index];
6976
src = f.url;
7077
71-
console.log(f.height, f.width);
72-
this.widthFirst = f.width >= f.height;
78+
this.aspectRatioDetection(f);
7379
7480
var fr = new FileReader();
7581
fr.onload = () => {
@@ -172,6 +178,20 @@ export default {
172178
173179
// console.log(type, button, movementX, movementY);
174180
},
181+
aspectRatioDetection(f) {
182+
this.widthFirst = f.width >= f.height;
183+
184+
const screen = {
185+
width: window.innerWidth,
186+
height: window.innerHeight,
187+
};
188+
const overSize = this.widthFirst
189+
? screen.width / screen.height > f.width / f.height
190+
: screen.width / screen.height < f.width / f.height;
191+
192+
if (this.widthFirst) this.widthFirst = this.widthFirst && !overSize;
193+
else this.widthFirst = this.widthFirst || overSize;
194+
},
175195
},
176196
watch: {
177197
index() {

src/index.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
html,
66
body {
7-
@apply absolute left-0 top-0 h-screen w-screen overflow-hidden;
7+
@apply absolute left-0 top-0 h-screen w-screen overflow-hidden bg-stone-900;
88
}

0 commit comments

Comments
 (0)