-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathPhotoGallery.vue
64 lines (62 loc) · 1.67 KB
/
PhotoGallery.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
<script>
import { ArrowPathIcon } from '@heroicons/vue/24/solid'
export default {
components: {
ArrowPathIcon
},
props: {
photos: {
type: Array,
required: true
}
},
data() {
return {
currentIndex: 0,
loading: false
}
},
methods: {
// NOTE: Assumes we have more then one image
nextPhoto(event) {
event.preventDefault()
this.loading = true
// cycle through the photos array
if (this.currentIndex === this.photos.length - 1) {
this.currentIndex = 0
} else {
this.currentIndex++
}
},
onImageLoad() {
// NOTE: we're really only doing this because of the dynamic image resizing
// on a cache miss there is a slight delay with imagekit as it resizes the image
this.loading = false
}
}
}
</script>
<template>
<div :class="{ loading: loading }" class="relative">
<a href="#" @click="nextPhoto">
<!-- use imagekit.io for dynamic image resizing,
this is using https://raw.githubusercontent.com/yuhonas/free-exercise-db/exercises
as the origin server -->
<img
:src="`https://ik.imagekit.io/yuhonas/${photos[currentIndex]}`"
:srcset="`https://ik.imagekit.io/yuhonas/${photos[currentIndex]} 850w, https://ik.imagekit.io/yuhonas/tr:w-250,h-180/${photos[currentIndex]} 200w`"
sizes="(min-width: 765px) 200px,
850px"
loading="lazy"
class="w-full object-cover rounded-t-lg p-2"
@load="onImageLoad"
/>
</a>
<ArrowPathIcon class="w-4 h-3 absolute top-4 left-4 text-white text-sm opacity-80" />
</div>
</template>
<style scoped>
.loading img {
filter: blur(2px);
}
</style>