-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathGallery.vue
95 lines (85 loc) · 2.2 KB
/
Gallery.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
<ImageModal ref="imageModal" :image="selectedImage" :next="gotoNextImage" :prev="gotoPrevImage" />
<div class="gallery-container">
<div class="gallery-item" v-for="(image, index) in galleryImages" :key="index">
<v-lazy-image :src="image" alt="random image" @click="openModal(image)" />
</div>
</div>
</template>
<style>
.v-lazy-image {
filter: blur(20px);
transition: filter 0.7s;
}
.v-lazy-image-loaded {
filter: blur(0);
}
.gallery-container {
column-gap: 1em;
}
.gallery-item {
display: inline-block;
margin: 0 0 1em;
width: 100%;
cursor: zoom-in;
}
.gallery-item>img {
width: inherit;
border-radius: 15px;
}
@media only screen and (min-width: 1024px) {
.gallery-container {
column-count: 4;
}
}
@media only screen and (max-width: 1023px) and (min-width: 768px) {
.gallery-container {
column-count: 3;
}
}
@media only screen and (max-width: 767px) and (min-width: 540px) {
.gallery-container {
column-count: 2;
}
}
</style>
<script>
import VLazyImage from "v-lazy-image";
import ImageModal from "./ImageModal.vue";
import { galleryImages } from "~/logic"
export default {
name: 'Gallery',
components: {
"v-lazy-image": VLazyImage,
ImageModal,
},
data() {
return {
galleryImages,
selectedImage: '',
}
},
methods: {
openModal(image) {
this.selectedImage = image;
this.$refs.imageModal.toggleModal();
},
gotoNextImage() {
const index = this.galleryImages.indexOf(this.selectedImage);
if (index === this.galleryImages.length - 1) {
this.selectedImage = this.galleryImages[0];
} else {
this.selectedImage = this.galleryImages[index + 1];
}
},
gotoPrevImage() {
const index = this.galleryImages.indexOf(this.selectedImage);
if (index === 0) {
this.selectedImage = this.galleryImages[this.galleryImages.length - 1];
} else {
this.selectedImage = this.galleryImages[index - 1];
}
},
},
}
</script>