Skip to content

Commit

Permalink
fix: image aspect-radio
Browse files Browse the repository at this point in the history
  • Loading branch information
huibizhang committed Jul 7, 2023
1 parent 40fca21 commit a4a73ae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function createWindow() {
// frame: false,
skipTaskbar: false,
transparent: false,
backgroundColor: "#1C1917",

resizable: true,
maximizable: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "photolisting",
"version": "0.2.2",
"version": "0.2.3",
"main": "main.js",
"scripts": {
"vite-dev": "cross-env NODE_ENV=dev vite",
Expand Down
26 changes: 23 additions & 3 deletions src/components/Lightbox.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div
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"
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"
:class="formOpen ? '' : 'pointer-events-none opacity-0'"
tabindex="0"
v-focus="formOpen"
Expand Down Expand Up @@ -58,6 +58,13 @@ export default {
};
},
mounted() {
window.addEventListener("resize", () => {
if (this.index >= 0 && this.index < this.files.length) {
const f = this.files[this.index];
this.aspectRatioDetection(f);
}
});
this.loadImage();
},
methods: {
Expand All @@ -68,8 +75,7 @@ export default {
const f = this.files[this.index];
src = f.url;
console.log(f.height, f.width);
this.widthFirst = f.width >= f.height;
this.aspectRatioDetection(f);
var fr = new FileReader();
fr.onload = () => {
Expand Down Expand Up @@ -172,6 +178,20 @@ export default {
// console.log(type, button, movementX, movementY);
},
aspectRatioDetection(f) {
this.widthFirst = f.width >= f.height;
const screen = {
width: window.innerWidth,
height: window.innerHeight,
};
const overSize = this.widthFirst
? screen.width / screen.height > f.width / f.height
: screen.width / screen.height < f.width / f.height;
if (this.widthFirst) this.widthFirst = this.widthFirst && !overSize;
else this.widthFirst = this.widthFirst || overSize;
},
},
watch: {
index() {
Expand Down
2 changes: 1 addition & 1 deletion src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

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

0 comments on commit a4a73ae

Please sign in to comment.