diff options
| author | taehoon <th.dev91@gmail.com> | 2019-10-18 16:04:17 -0400 |
|---|---|---|
| committer | taehoon <th.dev91@gmail.com> | 2019-10-22 07:17:02 -0400 |
| commit | 0396c6f29d29f3c9d743e00955a25e2d844b02da (patch) | |
| tree | f9cfaad787c55cbdfd73b6966d13a3240cf6e415 /src/components/gallery | |
| parent | 6c4d23714a42dd59843a8fb905150eed2d5db29d (diff) | |
keep image natural ratio in gallery row
Diffstat (limited to 'src/components/gallery')
| -rw-r--r-- | src/components/gallery/gallery.js | 24 | ||||
| -rw-r--r-- | src/components/gallery/gallery.vue | 2 |
2 files changed, 23 insertions, 3 deletions
diff --git a/src/components/gallery/gallery.js b/src/components/gallery/gallery.js index 3610f53d..e8cbb526 100644 --- a/src/components/gallery/gallery.js +++ b/src/components/gallery/gallery.js @@ -7,6 +7,11 @@ const Gallery = { 'nsfw', 'setMedia' ], + data () { + return { + sizes: {} + } + }, components: { Attachment }, computed: { rows () { @@ -23,12 +28,25 @@ const Gallery = { } return rows }, - rowStyle () { - return itemsPerRow => ({ 'padding-bottom': `${(100 / (itemsPerRow + 0.6))}%` }) - }, useContainFit () { return this.$store.state.config.useContainFit } + }, + methods: { + onNaturalSizeLoad (id, size) { + this.$set(this.sizes, id, size) + }, + rowStyle (itemsPerRow) { + return { 'padding-bottom': `${(100 / (itemsPerRow + 0.6))}%` } + }, + itemStyle (id) { + const size = this.sizes[id] + if (size) { + return { flex: size.width / size.height } + } else { + return {} + } + } } } diff --git a/src/components/gallery/gallery.vue b/src/components/gallery/gallery.vue index 3877987a..803ec471 100644 --- a/src/components/gallery/gallery.vue +++ b/src/components/gallery/gallery.vue @@ -18,6 +18,8 @@ :nsfw="nsfw" :attachment="attachment" :allow-play="false" + :natural-size-load="onNaturalSizeLoad.bind(null, attachment.id)" + :style="itemStyle(attachment.id)" /> </div> </div> |
