1
1
<template >
2
2
<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 "
4
4
:class =" formOpen ? '' : 'pointer-events-none opacity-0'"
5
5
tabindex =" 0"
6
6
v-focus =" formOpen"
@@ -58,6 +58,13 @@ export default {
58
58
};
59
59
},
60
60
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
+
61
68
this .loadImage ();
62
69
},
63
70
methods: {
@@ -68,8 +75,7 @@ export default {
68
75
const f = this .files [this .index ];
69
76
src = f .url ;
70
77
71
- console .log (f .height , f .width );
72
- this .widthFirst = f .width >= f .height ;
78
+ this .aspectRatioDetection (f);
73
79
74
80
var fr = new FileReader ();
75
81
fr .onload = () => {
@@ -172,6 +178,20 @@ export default {
172
178
173
179
// console.log(type, button, movementX, movementY);
174
180
},
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
+ },
175
195
},
176
196
watch: {
177
197
index () {
0 commit comments